Python:random module

From AIMSWiki

This page is under construction

Table of contents

Random as the name is a random variable generator and can be used to generate values within a given range or interval. Below are some basic applications and use of the command Random.

from random import *

OR

from RandomArray import *

Its application can be subdivided as below:

Integers

randint(a, b)

Choose a random integer in the range [a, b].

randrange(start, stop, step)

Choose a random integer from range(start, stop, step). The step argument is optional with default value 1.

Real numbers

gauss(mu, sigma)
normalvariate(mu, sigma)

Choose a random number from the normal distribution with mean mu and standard deviation sigma.

random()

Choose a random number uniformly from [0, 1)

random(n)

Choose n random numbers uniformly from [0,1) and presents it as an array of n-entries

uniform(a, b)

Choose a random number uniformly from [a, b)

Lists

choice(<list>)

Choose a random element from the list

shuffle(<list>)

Permute the numbers in the list randomly.


Return to the Python index