## Module `random`

### Purpose

- Support the generation of sequences of random values.

### Basics

- Random number generators use seed values to start up their random value sequences. The Random default constructor uses a seed value based on the current time. The difference in seed values from construction to construction causes the generator to produced different sequences.

- When generating a random value from an interval, all the values in the interval are equally likely to be drawn (unless explicitly stated otherwise)

- Strongly suggest you read the epistle on mathematical interval notation before checking out the below functions.

### Link(s)

### Essential functions

`random()`

- Returns a random float number from the interval [ 0, 1 )

- Sample usage:
`random.random()`

Returns a random float value

`v`

such that 0.0 ≤`v`

< 1.0

`uniform( a, b )`

- Returns a random float number from the [
`a`

,`b`

).

- Sample usage:
`random.uniform( 1.5, 7.25 )`

Returns a random float value

`v`

such that 1.5 ≤`v`

< 7.25.

`gauss( m, s )`

- Return a gaussian (normally distributed) float number, where the distribution has mean
`m`

and standard deviation`s`

.

- Sample usage:
`random.gauss( 0, 1 )`

Returns a normally distributed float

`v`

such that the distribution of its possible values has mean 0 and standard deviation 1 (standard bell-shaped curve)

`randrange( b )`

- Returns a random integer from the interval [ 0,
`b`

); that is, a base b number

- Sample usage:
`random.randrange( 10 )`

Returns an integer

`v`

such that 0 ≤`v`

< 10; that is, the base ten digits 0 through 9

`randrange( a, b )`

- Returns a random integer from the interval [
`a`

,`b`

)

- Sample usage:
`random.randrange( 31, 41 )`

Returns an integer

`v`

such that 31 ≤`v`

< 41.

`randrange( a, b, s )`

- Returns a random integer from the interval [
`a`

,`b`

) such that number equals`a`

`+`

`s`

`*`

`i`

for some integer`i`

.

- Sample usage:
`random.randrange( 1, 101, 2 )`

Returns a random odd number

`v`

between 1 and 100.

`choice( s )`

- Returns from a random value from the sequence
`s`

- Sample usage:
`random.choice( 'aeiou' )`

Returns a random vowel

- Sample usage:
`weekend = [ 'Saturday', 'Sunday' ] ; random.choice( weekend )`

Returns a random day of the weekend

`shuffle( s )`

- Randomly reorders the contents of
`s`

- Sample usage:
`rgb = [ 'Red', 'Green', 'Blue' ] ; random.shuffle( rgb )`

The contents of

`rgb`

are now in an unpredictable order

`random.seed( a )`

- Initializes the random number generator. Optional parameter
`a`

is used to configure the random number generator to a particular start state. This ability is useful during program delopment as it allows reproducibility during testing.

- Sample usage:
`random.seed()`

Uses the current time in the set up of the random number generator. As the current time is always changing, there should be different random numbers for each program run.

- Sample usage:
`random.seed( 1112 )`

Uses 1112 in the set up of the random number generator