Differences between revisions 1 and 4 (spanning 3 versions)
Revision 1 as of 2023-03-01 17:54:42
Size: 1552
Comment:
Revision 4 as of 2023-10-12 16:23:33
Size: 3645
Comment:
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:

'''`random`''' is a module for pseudo-random number generation.
Line 9: Line 11:
== BetaVariate == == Usage ==
Line 11: Line 13:
----



== Choice ==

----



== Choices ==

----



== ExpoVariate ==

----



== GammaVariate ==

----



== Gauss ==

Returns a pseudo-random `float` from a Gaussian distribution characterized by ''mu'' and ''sigma'' (in that order).

{{{
import random

r = random.gauss(0, 1)
}}}

----



== GetRandBits ==

----



== LogNormVariate ==

----



== NormalVariate ==

Returns a pseudo-random `float` from a normal distribution characterized by ''mu'' and ''sigma'' (in that order).

{{{
import random

r = random.normalvariate(0, 1)
}}}

----



== ParetoVariate ==

----



== RandBytes ==

----



== RandInt ==

----



== Random ==

Returns a pseudo-random `float` between 0 and 1, inclusive of 0.

{{{
import random

r = random.random()
}}}

----



== RandRange ==

----



== Sample ==

----



== Seed ==

----



== Shuffle ==

----



== Triangular ==

----



== Uniform ==

Returns a pseudo-random `float` between `a` and `b`, inclusive.

{{{
import random

r = random.uniform(0,1)
}}}

Note: due to floating point rounding, it is possible that the high end of the range will ''not'' be included.

----



== VonMisesVariate ==

----



== WeibullVariate ==
||'''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()` || ||
||`random()` ||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()` || ||
Line 173: Line 44:
[[https://pymotw.com/3/random/|Python Module of the Day article for random]]

Python Random

random is a module for pseudo-random number generation.


Usage

Function

Meaning

betavariate()

choice()

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()

random()

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()


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)