[code.view]

[top] / python / PyMOTW / random / random_choice.py

     #!/usr/bin/env python
     # encoding: utf-8
     #
     # Copyright (c) 2010 Doug Hellmann.  All rights reserved.
     #
     """Random choice
     """
     #end_pymotw_header
     
     import random
     import itertools
     
     outcomes = { 'heads':0,
                  'tails':0,
                  }
     sides = outcomes.keys()
     
     for i in range(10000):
         outcomes[ random.choice(sides) ] += 1
     
     print 'Heads:', outcomes['heads']
     print 'Tails:', outcomes['tails']
     

[top] / python / PyMOTW / random / random_choice.py

contact | logmethods.com