{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Pseudorandom Numbers"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"import random"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## `randrange`: Choosing a random integer from a range"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"4"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"random.randrange(1, 7)"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"6\n",
"3\n",
"1\n",
"3\n",
"6\n",
"5\n",
"1\n",
"6\n",
"2\n",
"1\n"
]
}
],
"source": [
"for i in range(10):\n",
" print(random.randrange(1, 7))"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"def freq_counting():\n",
" freqs = [0]*7\n",
" \n",
" for i in range(10_000):\n",
" i = random.randrange(1, 7)\n",
" freqs[i] += 1\n",
" \n",
" return freqs"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[0, 1660, 1669, 1595, 1614, 1730, 1732]"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"freq_counting()"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[0, 0, 0, 0, 0, 0, 0]"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"[0] * 7"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"`random` — Choosing a floar value betwen [0, 1)"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.14814459337185426\n",
"0.49330128344125834\n",
"0.7201026191844834\n",
"0.44049645580754715\n",
"0.5462267435743468\n",
"0.9133067624889044\n",
"0.6164370472183012\n",
"0.5243784065865988\n",
"0.0804888826164466\n",
"0.7397431834230711\n"
]
}
],
"source": [
"for i in range(10):\n",
" print(random.random())"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.772696121383678\n",
"1.8915668207915326\n",
"4.0905318722883885\n",
"9.554562581549762\n",
"4.862195900509207\n",
"4.850210528647299\n",
"1.661447418541353\n",
"7.104112088190107\n",
"7.435285967623393\n",
"1.9971129021033396\n"
]
}
],
"source": [
"for i in range(10):\n",
" print(random.random()*10)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Applying this to player serving"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Random number is 0.6310294170311493 -> player won the serve!\n",
"Random number is 0.010607819379212624 -> player won the serve!\n",
"Random number is 0.9843791914144882 -> player lost the serve!\n",
"Random number is 0.37549339281573924 -> player won the serve!\n",
"Random number is 0.15749266462333 -> player won the serve!\n",
"Random number is 0.887356939269537 -> player lost the serve!\n",
"Random number is 0.6341251193985786 -> player won the serve!\n",
"Random number is 0.1840303832257697 -> player won the serve!\n",
"Random number is 0.45362237330992217 -> player won the serve!\n",
"Random number is 0.28760850937588844 -> player won the serve!\n"
]
}
],
"source": [
"player_prob = 0.7 # 70% chance they win a serve\n",
"\n",
"for i in range(10):\n",
" r = random.random()\n",
" if r < player_prob:\n",
" print(f\"Random number is {r} -> player won the serve!\")\n",
" else:\n",
" print(f\"Random number is {r} -> player lost the serve!\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Choice"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [],
"source": [
"players = [\"A\", \"B\", \"C\", \"D\"]"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'D'"
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"random.choice(players)"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"A\n",
"B\n",
"B\n",
"C\n",
"A\n",
"A\n",
"D\n",
"B\n",
"D\n",
"A\n"
]
}
],
"source": [
"for i in range(10):\n",
" print(random.choice(players))"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {
"collapsed": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Help on module random:\n",
"\n",
"NAME\n",
" random - Random variable generators.\n",
"\n",
"MODULE REFERENCE\n",
" https://docs.python.org/3.8/library/random\n",
" \n",
" The following documentation is automatically generated from the Python\n",
" source files. It may be incomplete, incorrect or include features that\n",
" are considered implementation detail and may vary between Python\n",
" implementations. When in doubt, consult the module reference at the\n",
" location listed above.\n",
"\n",
"DESCRIPTION\n",
" integers\n",
" --------\n",
" uniform within range\n",
" \n",
" sequences\n",
" ---------\n",
" pick random element\n",
" pick random sample\n",
" pick weighted random sample\n",
" generate random permutation\n",
" \n",
" distributions on the real line:\n",
" ------------------------------\n",
" uniform\n",
" triangular\n",
" normal (Gaussian)\n",
" lognormal\n",
" negative exponential\n",
" gamma\n",
" beta\n",
" pareto\n",
" Weibull\n",
" \n",
" distributions on the circle (angles 0 to 2pi)\n",
" ---------------------------------------------\n",
" circular uniform\n",
" von Mises\n",
" \n",
" General notes on the underlying Mersenne Twister core generator:\n",
" \n",
" * The period is 2**19937-1.\n",
" * It is one of the most extensively tested generators in existence.\n",
" * The random() method is implemented in C, executes in a single Python step,\n",
" and is, therefore, threadsafe.\n",
"\n",
"CLASSES\n",
" _random.Random(builtins.object)\n",
" Random\n",
" SystemRandom\n",
" \n",
" class Random(_random.Random)\n",
" | Random(x=None)\n",
" | \n",
" | Random number generator base class used by bound module functions.\n",
" | \n",
" | Used to instantiate instances of Random to get generators that don't\n",
" | share state.\n",
" | \n",
" | Class Random can also be subclassed if you want to use a different basic\n",
" | generator of your own devising: in that case, override the following\n",
" | methods: random(), seed(), getstate(), and setstate().\n",
" | Optionally, implement a getrandbits() method so that randrange()\n",
" | can cover arbitrarily large ranges.\n",
" | \n",
" | Method resolution order:\n",
" | Random\n",
" | _random.Random\n",
" | builtins.object\n",
" | \n",
" | Methods defined here:\n",
" | \n",
" | __getstate__(self)\n",
" | # Issue 17489: Since __reduce__ was defined to fix #759889 this is no\n",
" | # longer called; we leave it here because it has been here since random was\n",
" | # rewritten back in 2001 and why risk breaking something.\n",
" | \n",
" | __init__(self, x=None)\n",
" | Initialize an instance.\n",
" | \n",
" | Optional argument x controls seeding, as for Random.seed().\n",
" | \n",
" | __reduce__(self)\n",
" | Helper for pickle.\n",
" | \n",
" | __setstate__(self, state)\n",
" | \n",
" | betavariate(self, alpha, beta)\n",
" | Beta distribution.\n",
" | \n",
" | Conditions on the parameters are alpha > 0 and beta > 0.\n",
" | Returned values range between 0 and 1.\n",
" | \n",
" | choice(self, seq)\n",
" | Choose a random element from a non-empty sequence.\n",
" | \n",
" | choices(self, population, weights=None, *, cum_weights=None, k=1)\n",
" | Return a k sized list of population elements chosen with replacement.\n",
" | \n",
" | If the relative weights or cumulative weights are not specified,\n",
" | the selections are made with equal probability.\n",
" | \n",
" | expovariate(self, lambd)\n",
" | Exponential distribution.\n",
" | \n",
" | lambd is 1.0 divided by the desired mean. It should be\n",
" | nonzero. (The parameter would be called \"lambda\", but that is\n",
" | a reserved word in Python.) Returned values range from 0 to\n",
" | positive infinity if lambd is positive, and from negative\n",
" | infinity to 0 if lambd is negative.\n",
" | \n",
" | gammavariate(self, alpha, beta)\n",
" | Gamma distribution. Not the gamma function!\n",
" | \n",
" | Conditions on the parameters are alpha > 0 and beta > 0.\n",
" | \n",
" | The probability distribution function is:\n",
" | \n",
" | x ** (alpha - 1) * math.exp(-x / beta)\n",
" | pdf(x) = --------------------------------------\n",
" | math.gamma(alpha) * beta ** alpha\n",
" | \n",
" | gauss(self, mu, sigma)\n",
" | Gaussian distribution.\n",
" | \n",
" | mu is the mean, and sigma is the standard deviation. This is\n",
" | slightly faster than the normalvariate() function.\n",
" | \n",
" | Not thread-safe without a lock around calls.\n",
" | \n",
" | getstate(self)\n",
" | Return internal state; can be passed to setstate() later.\n",
" | \n",
" | lognormvariate(self, mu, sigma)\n",
" | Log normal distribution.\n",
" | \n",
" | If you take the natural logarithm of this distribution, you'll get a\n",
" | normal distribution with mean mu and standard deviation sigma.\n",
" | mu can have any value, and sigma must be greater than zero.\n",
" | \n",
" | normalvariate(self, mu, sigma)\n",
" | Normal distribution.\n",
" | \n",
" | mu is the mean, and sigma is the standard deviation.\n",
" | \n",
" | paretovariate(self, alpha)\n",
" | Pareto distribution. alpha is the shape parameter.\n",
" | \n",
" | randint(self, a, b)\n",
" | Return random integer in range [a, b], including both end points.\n",
" | \n",
" | randrange(self, start, stop=None, step=1, _int=)\n",
" | Choose a random item from range(start, stop[, step]).\n",
" | \n",
" | This fixes the problem with randint() which includes the\n",
" | endpoint; in Python this is usually not what you want.\n",
" | \n",
" | sample(self, population, k)\n",
" | Chooses k unique random elements from a population sequence or set.\n",
" | \n",
" | Returns a new list containing elements from the population while\n",
" | leaving the original population unchanged. The resulting list is\n",
" | in selection order so that all sub-slices will also be valid random\n",
" | samples. This allows raffle winners (the sample) to be partitioned\n",
" | into grand prize and second place winners (the subslices).\n",
" | \n",
" | Members of the population need not be hashable or unique. If the\n",
" | population contains repeats, then each occurrence is a possible\n",
" | selection in the sample.\n",
" | \n",
" | To choose a sample in a range of integers, use range as an argument.\n",
" | This is especially fast and space efficient for sampling from a\n",
" | large population: sample(range(10000000), 60)\n",
" | \n",
" | seed(self, a=None, version=2)\n",
" | Initialize internal state from hashable object.\n",
" | \n",
" | None or no argument seeds from current time or from an operating\n",
" | system specific randomness source if available.\n",
" | \n",
" | If *a* is an int, all bits are used.\n",
" | \n",
" | For version 2 (the default), all of the bits are used if *a* is a str,\n",
" | bytes, or bytearray. For version 1 (provided for reproducing random\n",
" | sequences from older versions of Python), the algorithm for str and\n",
" | bytes generates a narrower range of seeds.\n",
" | \n",
" | setstate(self, state)\n",
" | Restore internal state from object returned by getstate().\n",
" | \n",
" | shuffle(self, x, random=None)\n",
" | Shuffle list x in place, and return None.\n",
" | \n",
" | Optional argument random is a 0-argument function returning a\n",
" | random float in [0.0, 1.0); if it is the default None, the\n",
" | standard random.random will be used.\n",
" | \n",
" | triangular(self, low=0.0, high=1.0, mode=None)\n",
" | Triangular distribution.\n",
" | \n",
" | Continuous distribution bounded by given lower and upper limits,\n",
" | and having a given mode value in-between.\n",
" | \n",
" | http://en.wikipedia.org/wiki/Triangular_distribution\n",
" | \n",
" | uniform(self, a, b)\n",
" | Get a random number in the range [a, b) or [a, b] depending on rounding.\n",
" | \n",
" | vonmisesvariate(self, mu, kappa)\n",
" | Circular data distribution.\n",
" | \n",
" | mu is the mean angle, expressed in radians between 0 and 2*pi, and\n",
" | kappa is the concentration parameter, which must be greater than or\n",
" | equal to zero. If kappa is equal to zero, this distribution reduces\n",
" | to a uniform random angle over the range 0 to 2*pi.\n",
" | \n",
" | weibullvariate(self, alpha, beta)\n",
" | Weibull distribution.\n",
" | \n",
" | alpha is the scale parameter and beta is the shape parameter.\n",
" | \n",
" | ----------------------------------------------------------------------\n",
" | Class methods defined here:\n",
" | \n",
" | __init_subclass__(**kwargs) from builtins.type\n",
" | Control how subclasses generate random integers.\n",
" | \n",
" | The algorithm a subclass can use depends on the random() and/or\n",
" | getrandbits() implementation available to it and determines\n",
" | whether it can generate random integers from arbitrarily large\n",
" | ranges.\n",
" | \n",
" | ----------------------------------------------------------------------\n",
" | Data descriptors defined here:\n",
" | \n",
" | __dict__\n",
" | dictionary for instance variables (if defined)\n",
" | \n",
" | __weakref__\n",
" | list of weak references to the object (if defined)\n",
" | \n",
" | ----------------------------------------------------------------------\n",
" | Data and other attributes defined here:\n",
" | \n",
" | VERSION = 3\n",
" | \n",
" | ----------------------------------------------------------------------\n",
" | Methods inherited from _random.Random:\n",
" | \n",
" | __getattribute__(self, name, /)\n",
" | Return getattr(self, name).\n",
" | \n",
" | getrandbits(self, k, /)\n",
" | getrandbits(k) -> x. Generates an int with k random bits.\n",
" | \n",
" | random(self, /)\n",
" | random() -> x in the interval [0, 1).\n",
" | \n",
" | ----------------------------------------------------------------------\n",
" | Static methods inherited from _random.Random:\n",
" | \n",
" | __new__(*args, **kwargs) from builtins.type\n",
" | Create and return a new object. See help(type) for accurate signature.\n",
" \n",
" class SystemRandom(Random)\n",
" | SystemRandom(x=None)\n",
" | \n",
" | Alternate random number generator using sources provided\n",
" | by the operating system (such as /dev/urandom on Unix or\n",
" | CryptGenRandom on Windows).\n",
" | \n",
" | Not available on all systems (see os.urandom() for details).\n",
" | \n",
" | Method resolution order:\n",
" | SystemRandom\n",
" | Random\n",
" | _random.Random\n",
" | builtins.object\n",
" | \n",
" | Methods defined here:\n",
" | \n",
" | getrandbits(self, k)\n",
" | getrandbits(k) -> x. Generates an int with k random bits.\n",
" | \n",
" | getstate = _notimplemented(self, *args, **kwds)\n",
" | \n",
" | random(self)\n",
" | Get the next random number in the range [0.0, 1.0).\n",
" | \n",
" | seed(self, *args, **kwds)\n",
" | Stub method. Not used for a system random number generator.\n",
" | \n",
" | setstate = _notimplemented(self, *args, **kwds)\n",
" | \n",
" | ----------------------------------------------------------------------\n",
" | Methods inherited from Random:\n",
" | \n",
" | __getstate__(self)\n",
" | # Issue 17489: Since __reduce__ was defined to fix #759889 this is no\n",
" | # longer called; we leave it here because it has been here since random was\n",
" | # rewritten back in 2001 and why risk breaking something.\n",
" | \n",
" | __init__(self, x=None)\n",
" | Initialize an instance.\n",
" | \n",
" | Optional argument x controls seeding, as for Random.seed().\n",
" | \n",
" | __reduce__(self)\n",
" | Helper for pickle.\n",
" | \n",
" | __setstate__(self, state)\n",
" | \n",
" | betavariate(self, alpha, beta)\n",
" | Beta distribution.\n",
" | \n",
" | Conditions on the parameters are alpha > 0 and beta > 0.\n",
" | Returned values range between 0 and 1.\n",
" | \n",
" | choice(self, seq)\n",
" | Choose a random element from a non-empty sequence.\n",
" | \n",
" | choices(self, population, weights=None, *, cum_weights=None, k=1)\n",
" | Return a k sized list of population elements chosen with replacement.\n",
" | \n",
" | If the relative weights or cumulative weights are not specified,\n",
" | the selections are made with equal probability.\n",
" | \n",
" | expovariate(self, lambd)\n",
" | Exponential distribution.\n",
" | \n",
" | lambd is 1.0 divided by the desired mean. It should be\n",
" | nonzero. (The parameter would be called \"lambda\", but that is\n",
" | a reserved word in Python.) Returned values range from 0 to\n",
" | positive infinity if lambd is positive, and from negative\n",
" | infinity to 0 if lambd is negative.\n",
" | \n",
" | gammavariate(self, alpha, beta)\n",
" | Gamma distribution. Not the gamma function!\n",
" | \n",
" | Conditions on the parameters are alpha > 0 and beta > 0.\n",
" | \n",
" | The probability distribution function is:\n",
" | \n",
" | x ** (alpha - 1) * math.exp(-x / beta)\n",
" | pdf(x) = --------------------------------------\n",
" | math.gamma(alpha) * beta ** alpha\n",
" | \n",
" | gauss(self, mu, sigma)\n",
" | Gaussian distribution.\n",
" | \n",
" | mu is the mean, and sigma is the standard deviation. This is\n",
" | slightly faster than the normalvariate() function.\n",
" | \n",
" | Not thread-safe without a lock around calls.\n",
" | \n",
" | lognormvariate(self, mu, sigma)\n",
" | Log normal distribution.\n",
" | \n",
" | If you take the natural logarithm of this distribution, you'll get a\n",
" | normal distribution with mean mu and standard deviation sigma.\n",
" | mu can have any value, and sigma must be greater than zero.\n",
" | \n",
" | normalvariate(self, mu, sigma)\n",
" | Normal distribution.\n",
" | \n",
" | mu is the mean, and sigma is the standard deviation.\n",
" | \n",
" | paretovariate(self, alpha)\n",
" | Pareto distribution. alpha is the shape parameter.\n",
" | \n",
" | randint(self, a, b)\n",
" | Return random integer in range [a, b], including both end points.\n",
" | \n",
" | randrange(self, start, stop=None, step=1, _int=)\n",
" | Choose a random item from range(start, stop[, step]).\n",
" | \n",
" | This fixes the problem with randint() which includes the\n",
" | endpoint; in Python this is usually not what you want.\n",
" | \n",
" | sample(self, population, k)\n",
" | Chooses k unique random elements from a population sequence or set.\n",
" | \n",
" | Returns a new list containing elements from the population while\n",
" | leaving the original population unchanged. The resulting list is\n",
" | in selection order so that all sub-slices will also be valid random\n",
" | samples. This allows raffle winners (the sample) to be partitioned\n",
" | into grand prize and second place winners (the subslices).\n",
" | \n",
" | Members of the population need not be hashable or unique. If the\n",
" | population contains repeats, then each occurrence is a possible\n",
" | selection in the sample.\n",
" | \n",
" | To choose a sample in a range of integers, use range as an argument.\n",
" | This is especially fast and space efficient for sampling from a\n",
" | large population: sample(range(10000000), 60)\n",
" | \n",
" | shuffle(self, x, random=None)\n",
" | Shuffle list x in place, and return None.\n",
" | \n",
" | Optional argument random is a 0-argument function returning a\n",
" | random float in [0.0, 1.0); if it is the default None, the\n",
" | standard random.random will be used.\n",
" | \n",
" | triangular(self, low=0.0, high=1.0, mode=None)\n",
" | Triangular distribution.\n",
" | \n",
" | Continuous distribution bounded by given lower and upper limits,\n",
" | and having a given mode value in-between.\n",
" | \n",
" | http://en.wikipedia.org/wiki/Triangular_distribution\n",
" | \n",
" | uniform(self, a, b)\n",
" | Get a random number in the range [a, b) or [a, b] depending on rounding.\n",
" | \n",
" | vonmisesvariate(self, mu, kappa)\n",
" | Circular data distribution.\n",
" | \n",
" | mu is the mean angle, expressed in radians between 0 and 2*pi, and\n",
" | kappa is the concentration parameter, which must be greater than or\n",
" | equal to zero. If kappa is equal to zero, this distribution reduces\n",
" | to a uniform random angle over the range 0 to 2*pi.\n",
" | \n",
" | weibullvariate(self, alpha, beta)\n",
" | Weibull distribution.\n",
" | \n",
" | alpha is the scale parameter and beta is the shape parameter.\n",
" | \n",
" | ----------------------------------------------------------------------\n",
" | Class methods inherited from Random:\n",
" | \n",
" | __init_subclass__(**kwargs) from builtins.type\n",
" | Control how subclasses generate random integers.\n",
" | \n",
" | The algorithm a subclass can use depends on the random() and/or\n",
" | getrandbits() implementation available to it and determines\n",
" | whether it can generate random integers from arbitrarily large\n",
" | ranges.\n",
" | \n",
" | ----------------------------------------------------------------------\n",
" | Data descriptors inherited from Random:\n",
" | \n",
" | __dict__\n",
" | dictionary for instance variables (if defined)\n",
" | \n",
" | __weakref__\n",
" | list of weak references to the object (if defined)\n",
" | \n",
" | ----------------------------------------------------------------------\n",
" | Data and other attributes inherited from Random:\n",
" | \n",
" | VERSION = 3\n",
" | \n",
" | ----------------------------------------------------------------------\n",
" | Methods inherited from _random.Random:\n",
" | \n",
" | __getattribute__(self, name, /)\n",
" | Return getattr(self, name).\n",
" | \n",
" | ----------------------------------------------------------------------\n",
" | Static methods inherited from _random.Random:\n",
" | \n",
" | __new__(*args, **kwargs) from builtins.type\n",
" | Create and return a new object. See help(type) for accurate signature.\n",
"\n",
"FUNCTIONS\n",
" betavariate(alpha, beta) method of Random instance\n",
" Beta distribution.\n",
" \n",
" Conditions on the parameters are alpha > 0 and beta > 0.\n",
" Returned values range between 0 and 1.\n",
" \n",
" choice(seq) method of Random instance\n",
" Choose a random element from a non-empty sequence.\n",
" \n",
" choices(population, weights=None, *, cum_weights=None, k=1) method of Random instance\n",
" Return a k sized list of population elements chosen with replacement.\n",
" \n",
" If the relative weights or cumulative weights are not specified,\n",
" the selections are made with equal probability.\n",
" \n",
" expovariate(lambd) method of Random instance\n",
" Exponential distribution.\n",
" \n",
" lambd is 1.0 divided by the desired mean. It should be\n",
" nonzero. (The parameter would be called \"lambda\", but that is\n",
" a reserved word in Python.) Returned values range from 0 to\n",
" positive infinity if lambd is positive, and from negative\n",
" infinity to 0 if lambd is negative.\n",
" \n",
" gammavariate(alpha, beta) method of Random instance\n",
" Gamma distribution. Not the gamma function!\n",
" \n",
" Conditions on the parameters are alpha > 0 and beta > 0.\n",
" \n",
" The probability distribution function is:\n",
" \n",
" x ** (alpha - 1) * math.exp(-x / beta)\n",
" pdf(x) = --------------------------------------\n",
" math.gamma(alpha) * beta ** alpha\n",
" \n",
" gauss(mu, sigma) method of Random instance\n",
" Gaussian distribution.\n",
" \n",
" mu is the mean, and sigma is the standard deviation. This is\n",
" slightly faster than the normalvariate() function.\n",
" \n",
" Not thread-safe without a lock around calls.\n",
" \n",
" getrandbits(k, /) method of Random instance\n",
" getrandbits(k) -> x. Generates an int with k random bits.\n",
" \n",
" getstate() method of Random instance\n",
" Return internal state; can be passed to setstate() later.\n",
" \n",
" lognormvariate(mu, sigma) method of Random instance\n",
" Log normal distribution.\n",
" \n",
" If you take the natural logarithm of this distribution, you'll get a\n",
" normal distribution with mean mu and standard deviation sigma.\n",
" mu can have any value, and sigma must be greater than zero.\n",
" \n",
" normalvariate(mu, sigma) method of Random instance\n",
" Normal distribution.\n",
" \n",
" mu is the mean, and sigma is the standard deviation.\n",
" \n",
" paretovariate(alpha) method of Random instance\n",
" Pareto distribution. alpha is the shape parameter.\n",
" \n",
" randint(a, b) method of Random instance\n",
" Return random integer in range [a, b], including both end points.\n",
" \n",
" random() method of Random instance\n",
" random() -> x in the interval [0, 1).\n",
" \n",
" randrange(start, stop=None, step=1, _int=) method of Random instance\n",
" Choose a random item from range(start, stop[, step]).\n",
" \n",
" This fixes the problem with randint() which includes the\n",
" endpoint; in Python this is usually not what you want.\n",
" \n",
" sample(population, k) method of Random instance\n",
" Chooses k unique random elements from a population sequence or set.\n",
" \n",
" Returns a new list containing elements from the population while\n",
" leaving the original population unchanged. The resulting list is\n",
" in selection order so that all sub-slices will also be valid random\n",
" samples. This allows raffle winners (the sample) to be partitioned\n",
" into grand prize and second place winners (the subslices).\n",
" \n",
" Members of the population need not be hashable or unique. If the\n",
" population contains repeats, then each occurrence is a possible\n",
" selection in the sample.\n",
" \n",
" To choose a sample in a range of integers, use range as an argument.\n",
" This is especially fast and space efficient for sampling from a\n",
" large population: sample(range(10000000), 60)\n",
" \n",
" seed(a=None, version=2) method of Random instance\n",
" Initialize internal state from hashable object.\n",
" \n",
" None or no argument seeds from current time or from an operating\n",
" system specific randomness source if available.\n",
" \n",
" If *a* is an int, all bits are used.\n",
" \n",
" For version 2 (the default), all of the bits are used if *a* is a str,\n",
" bytes, or bytearray. For version 1 (provided for reproducing random\n",
" sequences from older versions of Python), the algorithm for str and\n",
" bytes generates a narrower range of seeds.\n",
" \n",
" setstate(state) method of Random instance\n",
" Restore internal state from object returned by getstate().\n",
" \n",
" shuffle(x, random=None) method of Random instance\n",
" Shuffle list x in place, and return None.\n",
" \n",
" Optional argument random is a 0-argument function returning a\n",
" random float in [0.0, 1.0); if it is the default None, the\n",
" standard random.random will be used.\n",
" \n",
" triangular(low=0.0, high=1.0, mode=None) method of Random instance\n",
" Triangular distribution.\n",
" \n",
" Continuous distribution bounded by given lower and upper limits,\n",
" and having a given mode value in-between.\n",
" \n",
" http://en.wikipedia.org/wiki/Triangular_distribution\n",
" \n",
" uniform(a, b) method of Random instance\n",
" Get a random number in the range [a, b) or [a, b] depending on rounding.\n",
" \n",
" vonmisesvariate(mu, kappa) method of Random instance\n",
" Circular data distribution.\n",
" \n",
" mu is the mean angle, expressed in radians between 0 and 2*pi, and\n",
" kappa is the concentration parameter, which must be greater than or\n",
" equal to zero. If kappa is equal to zero, this distribution reduces\n",
" to a uniform random angle over the range 0 to 2*pi.\n",
" \n",
" weibullvariate(alpha, beta) method of Random instance\n",
" Weibull distribution.\n",
" \n",
" alpha is the scale parameter and beta is the shape parameter.\n",
"\n",
"DATA\n",
" __all__ = ['Random', 'seed', 'random', 'uniform', 'randint', 'choice',...\n",
"\n",
"FILE\n",
" /usr/local/Cellar/python@3.8/3.8.12_1/Frameworks/Python.framework/Versions/3.8/lib/python3.8/random.py\n",
"\n",
"\n"
]
}
],
"source": [
"help(random)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.12"
}
},
"nbformat": 4,
"nbformat_minor": 4
}