# Notes for Monday, October 2

# Random numbers in Python
#-------------------------------------------------------------
# The random module contains several useful functions for
# generating random numbers.  The ones to know about are:
#
# random.uniform(a, b) returns a random REAL number from a up
# to but not including b.  For example, random.uniform(1, 2)
# might return 1.234, 1.999, 1.000, or 1.724, but never 2.000
# exactly.
#
# random.randrange(a) returns a random INTEGER from 0 up
# to but not including a.  For example, random.randrange(10)
# returns integers from 0 to 9.
#
# random.randrange(a, b) returns a random integer from a up to
# but not including b.  For example, random.randrange(1, 10)
# returns a random integer from 1 to 9.  In general, randrange
# is analogous to Python's range function.
#
# random.randrange(a, b, c) returns a random integer from a
# up to but not including b, using a step size of c.  For
# example, random.randrange(1, 10, 2) returns a random odd
# integer from 1 to 9, which is the same as picking a number
# at random from the list [1, 3, 5, 7, 9] generated by
# range(1, 10, 2).

#-------------------------------------------------------------

import random

# This program tests the behavior of the random number
# generator to make sure it produces a uniform distribution
# of random values in the range 0 to 9.

def testRandom():

    # how many trials to perform?
    trials = input("Enter number of trials: ")

    # initialize our list of digit totals
    counts = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

    # generate random digits and keep track of their totals
    for i in range(trials):
        digit = random.randrange(10)
        currentCount = counts[digit]
        counts[digit] = currentCount + 1

    print "totals for each digit:"
    print counts
    print

    # print out the percentages
    for digit in range(10):
        total = counts[digit]
        percent = float(total) / trials * 100
        print "The percentage of %d is %.2f%%" % (digit, percent)
