Demonstrates random number generation : Random « Development « Python






Demonstrates random number generation

 

import random

# generate random numbers 1 - 6
die1 = random.randrange(6) + 1    
die2 = random.randrange(6) + 1

total = die1 + die2

print "You rolled a", die1, "and a", die2, "for a total of", total

raw_input("\n\nPress the enter key to exit.")

   
  








Related examples in the same category

1.Random integers produced by randrange.Random integers produced by randrange.
2.random number generationrandom number generation
3.Random Choice Random Choice
4.Sampling without replacementSampling without replacement
5.Random int value
6.Random floatRandom float
7.Random string value
8.Demonstrates the range() functionDemonstrates the range() function
9.Random integer chosen from range(6)Random integer chosen from range(6)