P. Random - JulTob/Python GitHub Wiki

🐍 Random

🚧 Do not use for security.

import random

num = random.random()           # 0..1   float
num = random.random() * 100     # 0..100 float

num = random.randint(0,9)       # 0..9   int

num = random.randrange(0,100,5) # 0,5,10,15,20.,.100

colour = random.choice(["red","black","green"])

num = random.uniform(3,7)   # uniform 3..7

bell = random.normalvariate(3,1) 
   # Random number from normal distribution giving mean and stnd dev
   ## μ = 3, σ = 1

if (random.randint(1,2) == 1):
  print("Heads")
else:
  print("Tails")

System Random

os.urandom