[Tutor] Random

Wesley J. Chun wesc@alpha.ece.ucsb.edu
Mon, 7 Feb 2000 10:42:43 -0800 (PST)


    > From: "Alexandre Passos" <atp@bahianet.com.br>
    > Date: Mon, 7 Feb 2000 16:17:16 -0200
    > 
    > How can I make a random number?


take a look at the 'whrandom' module.

in particular, there are mainly 5 functions of interest:

whrandom()	random number generator (RNG) constructor
randint(a,b)	retuns a random int i such that a <= i <= b
uniform(a,b)	retuns a random float f such that a <= i < b
random(a,b)	retuns a random float f such that 0.0 <= f < 1.0
choice()	choose a random sequence element

example:

>>> import whrandom
>>> rng = whrandom.whrandom()
>>> rng.randint(3, 40)
36
>>> rng.randint(3, 40)
23
>>> rng.randint(3, 40)
12
>>> rng.randint(3, 40)
18
>>> rng.randint(3, 40)
27

hope this helps!!

-wesley