dimanche 13 décembre 2015

Too similar results from random generation python

I trying to get some random results from some options in code with many attempts. The problem is, that I have very similar results. Please, see my results:

./run.py
Option Option 4 have 333478 counts which is 16.674
Option Option 5 have 333631 counts which is 16.682
Option Option 3 have 332898 counts which is 16.645
Option Option 2 have 333555 counts which is 16.678
Option Option 6 have 332732 counts which is 16.637
Option Option 1 have 333706 counts which is 16.685

Here are the code:

#!/usr/bin/python3

import sys
import random
import time

options = ('Option 1', 'Option 2', 'Option 3', 'Option 4', 'Option 5', 'Option 6')
attempts = 2000000
step = 1000000

rng = random.SystemRandom()

counts = {}
for option in options:
  counts.update({option:0})

start = time.time()
for i in range(0, attempts):
  index = options[rng.randint(0, (len(options)-1))]
  count = counts[index]
  counts.update({index:count+1})
  if (i % step == 0 and i > 0):
    percent = float(round(i / attempts * 100, 3))
    elapsed = time.strftime('%H:%M:%S', time.gmtime(time.time() - start))
    print ('Step %d from %d which is %02d percent until %s' %(i, attempts, percent, elapsed ))

for key,value in counts.items():
  percent = float(round(value / attempts * 100, 3))
  print ('Option %s have %s counts which is %s' %(key, value, percent ) )

sys.exit(0)

It's possible to have more different results? If you will throw by dice, I'm absolutly sure that options will be much different that 16% to one of all. Thanks for any ideas

FriskyFox




Aucun commentaire:

Enregistrer un commentaire