Differences between revisions 4 and 5
Revision 4 as of 2023-10-12 16:23:33
Size: 3645
Comment:
Revision 5 as of 2023-12-09 01:45:49
Size: 4898
Comment:
Deletions are marked like this. Additions are marked like this.
Line 13: Line 13:
||'''Function''' ||'''Meaning''' ||
||`betavariate()` || ||
||`choice()`   || ||
||`choices()` || ||
||`expovariate()` || ||
||`gammavariate()` || ||
||`gauss(mu, sigma)` ||return a [[Python/Builtins/Types#Float|float]] from the Gaussian distribution characterized by ''mu'' and ''sigma''||
||`getrandbits()` || ||
||`lognormvariate()` || ||
||`normalvariate(mu, sigma)`||return a float from the normal distribution characterized by ''mu'' and ''sigma'' ||
||`paretovariate()` || ||
||`randbytes()` || ||
||`randint()`     || ||
||`ran
dom()` ||return a float between 0 and 1, inclusive of 0 ||
||`randrange()` || ||
||`sample()` || ||
||`seed()` || ||
||`shuffle()`   || ||
||`triangular()` || ||
||`uniform(a, b)` ||return a float between ''a'' and ''b'', inclusive (except when floating point rounding hits the high value) ||
||`vonmisesvariate()` || ||
||`weibullvariate()` || ||
||'''Function''' ||'''Meaning'''                                                 ||
||`betavariate()` ||                                                 ||
||`binomialvariate(n, p)` ||return the [[Python/Builtins/Types#Int|int]] expected number of successes given a binomial distribution over probability `p` (between 0 and 1) and given `n` trials
||
||`choice(it)` ||return a random element of [[Python/Collections/Abc#Sequence|sequence]] `it` ||
||`choices()` ||                                                 ||
||`expovariate()` ||                                                 ||
||`gammavariate()` ||                                                 ||
||`gauss(mu, sigma)` ||return a [[Python/Builtins/Types#Float|float]] from the Gaussian distribution characterized by ''mu'' and ''sigma''                                                ||
||`getrandbits()` ||                                                 ||
||`lognormvariate()` ||                                                 ||
||`normalvariate(mu, sigma)`||return a float from the normal distribution characterized by ''mu'' and ''sigma''                                                 ||
||`paretovariate()` ||                                                 ||
||`randbytes()` ||                                                 ||
||`randint(a, b)` ||return an int from a discrete uniform distribution between ''a'' and ''b'', inclusive          ||
||`random()`    ||return a float between 0 and 1, inclusive of 0 ||
||`randrange()` ||return an int from a range; takes same arguments as `range()` (i.e. `range(10)`; `range(1,11,2)`)
||
||`sample()` ||                                                 ||
||`seed()` ||                                                 ||
||`shuffle(it)` ||randomize the order of elements in [[Python/Collections/Abc#MutableSequence|mutable sequence]] `it` in place ||
||`triangular()` ||                                                 ||
||`uniform(a, b)` ||return a float between ''a'' and ''b'', inclusive (except when floating point rounding hits the high value)                                                 ||
||`vonmisesvariate()` ||                                                 ||
||`weibullvariate()` ||                                                 ||

Python Random

random is a module for pseudo-random number generation.


Usage

Function

Meaning

betavariate()

binomialvariate(n, p)

return the int expected number of successes given a binomial distribution over probability p (between 0 and 1) and given n trials

choice(it)

return a random element of sequence it

choices()

expovariate()

gammavariate()

gauss(mu, sigma)

return a float from the Gaussian distribution characterized by mu and sigma

getrandbits()

lognormvariate()

normalvariate(mu, sigma)

return a float from the normal distribution characterized by mu and sigma

paretovariate()

randbytes()

randint(a, b)

return an int from a discrete uniform distribution between a and b, inclusive

random()

return a float between 0 and 1, inclusive of 0

randrange()

return an int from a range; takes same arguments as range() (i.e. range(10); range(1,11,2))

sample()

seed()

shuffle(it)

randomize the order of elements in mutable sequence it in place

triangular()

uniform(a, b)

return a float between a and b, inclusive (except when floating point rounding hits the high value)

vonmisesvariate()

weibullvariate()


See also

Python random module documentation

Python Module of the Day article for random


CategoryRicottone

Python/Random (last edited 2023-12-09 01:48:58 by DominicRicottone)