Python random snippets

Documentation

Import directives

In [1]:
import random

Return a random floating point number in the range [0.0, 1.0)

In [2]:
random.random()
Out[2]:
0.7544006466383502

Return a random integer from a given interval

In [3]:
min_value = 0
max_value = 10
random.randint(min_value, max_value)
Out[3]:
8