http://effbot.org/pyfaq/how-do-i-generate-random-numbers-in-python.htm
How do I generate random numbers in Python?
The standard random module implements a random number generator. Usage is simple:
import random print random.random()
This prints a random floating point number in the range [0, 1) (that is, between 0 and 1, including 0.0 but always smaller than 1.0).
There are also many other specialized generators in this module, such as:
- randrange(a, b) chooses an integer in the range [a, b).
- uniform(a, b) chooses a floating point number in the range [a, b).
- normalvariate(mean, sdev) samples the normal (Gaussian) distribution.
Some higher-level functions operate on sequences directly, such as:
- choice(S) chooses a random element from a given sequence (the sequence must have a known length).
- shuffle(L) shuffles a list in-place, i.e. permutes it randomly
There’s also a Random class you can instantiate to create independent multiple random number generators.
CATEGORY: library
'Programming' 카테고리의 다른 글
Python Mapping Types — dict (0) | 2012.05.29 |
---|---|
Python if statements (0) | 2012.05.29 |
Python is Cool (and Perl is not), Especially for C/C++ Programmers (0) | 2012.05.29 |
Is it possible to implement a Python for range loop without an iterator variable? (0) | 2012.05.29 |
PyDev - a Python IDE for Eclipse (0) | 2012.05.28 |