'''
Created on Feb 13, 2011

@author: ola
'''
import random


_DIESIDES = 6

def dice():
    '''
    Returns a random roll of two 'fair' die
    '''
    a = random.randint(1,_DIESIDES)
    b = random.randint(1,_DIESIDES)
    return a+b


def get_bar(length):
    '''
    Return String/bar for graphing based on max-bar = 60
    '''
    return '*'*int(length*60)


def generate_rolls(n):
    '''
    Return list of n simulated dice rolls
    '''
    return [dice() for i in range(0,n)]


def print_stats(rolls):
    '''
    Print statistics for rolls, a list of simulated dice rolls
    rolls is a list of int values representing dice rolls
    '''
    counters = [0]*(2*_DIESIDES+1)
    for roll in rolls:
        counters[roll] += 1
    mx = max(counters)
    for i in range(2,2*_DIESIDES+1):
        print "%3d %s %5d" % (i,get_bar(counters[i]*1.0/mx),counters[i])



print_stats(generate_rolls(100000))

    
"""
One run of program shown below:

  2 **********  2784
  3 *******************  5472
  4 ******************************  8353
  5 *************************************** 10959
  6 ************************************************** 14002
  7 ************************************************************ 16515
  8 ************************************************** 13973
  9 **************************************** 11174
 10 ******************************  8327
 11 ********************  5693
 12 *********  2748
"""
