The standard library random module provides tools of:
import random print( random.random() ) print( random.random() ) # Random floats, integers, choices, shuffles print( random.randint(1, 10) ) print( random.randint(1, 10) )
This module can also choose an item at random from a sequence, and shuffle a list of items randomly:
import random print( random.choice(['Json', 'Database', 'Web']) ) print( random.choice(['Json', 'Database', 'Web']) ) suits = ['hearts', 'clubs', 'diamonds', 'spades'] print( random.shuffle(suits) ) print( random.shuffle(suits) ) print( suits )# from www . j ava 2s . c o m