random Module

A Python module in the standard library that allows you to apply randomness to things.

Random numbers #

  • random.int() ?

Random lists #

  • random.choice()
  • random.shuffle()
>>> import random
>>> pets = ['Dog', 'Cat', 'Moose']
>>> random.choice(pets)
'Moose'
>>> random.choice(pets)
'Cat'
>>> import random
>>> people = ['Alice', 'Bob', 'Carol', 'David']
>>> random.shuffle(people)
>>> people
['Carol', 'Alice', 'David', 'Bob']
>>> random.shuffle(people)
>>> people
['Bob', 'Carol', 'David', 'Alice']

Shuffle real smooth…