Most computer programs do the same thing every time they execute, given the same inputs, so they are said to be deterministic. Deterministic is usually a good thing, since we expect the same calculation to yield the same result. For some applications, though, we want the computer to be unpredictable. Games are an obvious example, but there are more.

Making a program truly nondeterministic turns out to be not so easy, but there are ways to make it at least seem nondeterministic. One of them is to use algorithms that generate pseudorandom numbers. Pseudorandom numbers are not truly random because they are generated by a deterministic computation, but just by looking at the numbers it is all but impossible to distinguish them from random. The random module provides functions that generate pseudorandom numbers.

The function random returns a random float between 0.0 and 1.0. Each time you call random, you get the next number in a long series.

The function randint takes parameters low and high and returns an integer between low and high (including both). And to choose an element from a sequence at random, you can use choice:

The random module also provides functions to generate random values from continuous distributions including Gaussian, exponential, gamma, and a few more.

from Thinking in Python

Random numbers的更多相关文章

  1. C++ Standard-Library Random Numbers

    Extracted from Section 17.4 Random Numbers, C++ Primer 5th. Ed. The random-number library generates ...

  2. Random Numbers Gym - 101466K dfs序+线段树

    Tamref love random numbers, but he hates recurrent relations, Tamref thinks that mainstream random g ...

  3. Generating Gaussian Random Numbers(转)

    Generating Gaussian Random Numbers http://www.taygeta.com/random/gaussian.html This note is about th ...

  4. 2017 ACM-ICPC, Universidad Nacional de Colombia Programming Contest K - Random Numbers (dfs序 线段树+数论)

    Tamref love random numbers, but he hates recurrent relations, Tamref thinks that mainstream random g ...

  5. [Swift] 随机数 | Random numbers

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  6. [Functional Programming] Pull Many Random Numbers in a Single State ADT Transaction

    We have the ability to select a single random card from a pile of twelve cards, but we would like to ...

  7. [Python] Generating random numbers using numpy lib

    import numpy as np def test_run(): data=np.random.random((3,4)) """ [[ 0.80150549 0.9 ...

  8. K. Random Numbers(Gym 101466K + 线段树 + dfs序 + 快速幂 + 唯一分解)

    题目链接:http://codeforces.com/gym/101466/problem/K 题目: 题意: 给你一棵有n个节点的树,根节点始终为0,有两种操作: 1.RAND:查询以u为根节点的子 ...

  9. 【DFS序+树状数组】BNUOJ 52733 Random Numbers

    http://acm.bnu.edu.cn/v3/problem_show.php?pid=52733 [题意] 给定一棵树,这棵树每个点都有一个点权,标号从0开始,0是根结点 修改操作: SEED ...

随机推荐

  1. 玩转oracle学习第六天

     1.上节回想 2.PL/SQL的介绍 3.PL/SQL的基础 理解oracle的pl/sql概念 掌握PL/SQL编程技术(包含编写过程,函数,触发器.包... ) PL/SQL是什么? PL/ ...

  2. 安全风控的CAP原理和BASE思想

    CAP原理最多实现两个,需要牺牲一个来满足其他两个:

  3. sqlplus登录提示:ORA-12162:TNS:net service name is incorrectly specified错误

    [root@localhost ~]# su - oracle [oracle@localhost ~]$ sqlplus '/as sysdba' SQL*Plus: Release 11.2.0. ...

  4. TSNE——目前最好的降维方法

    转自:http://blog.csdn.net/u012162613/article/details/45920827 1.流形学习的概念 流形学习方法(Manifold Learning),简称流形 ...

  5. Wireshark filter语法

    过滤器语法 ------------------------------------------------------------- 最简单的过滤允许你检查一个协议或者字段的存在.如果你想查看所有的 ...

  6. C#调用GPG命令进行加密解密文件操作

    public void GPG() { string password = "1234567890"; System.Diagnostics.ProcessStartInfo ps ...

  7. C#的常见算法(面试)(转)

    一.求以下表达式的值,写出您想到的一种或几种实现方法: 1-2+3-4+……+m //方法一,通过顺序规律写程序,同时也知道flag标志位的重要性. static int F1(int m) { ; ...

  8. Android封装类似微信的顶部TitleBar弹出的PopupWindow代码

    Android仿微信顶部titlebar,点击加号弹出的PopupWindow,是封装好的PopupWindow,直接拿来用即可,先看效果图:  调用代码非常简单,这是MainActivity的代码: ...

  9. 利用canvas制作简单的logo

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  10. 【原创】VSFTP: Login failure: 530 Login incorrect的解决办法

    1.修改/etc/vsftpd/ftpusers和/etc/vsftpd/user_list中关于root的行,注释掉即可: 2.关闭SELinux:如果不想关闭的话,可以打开home项的布林值:se ...