To test how random the numbers that python generates are, i wrote this:
import random
l=[]
lshuf=[]
for x in range(0,101):
lshuf.append(x)
for x in range (0,100000):
l.append(lshuf[random.randrange(0,101)])
l2=[]
for x in range(0,101):
l2.append(0)
for x in l:
l2[l[x]]+=1
Basically It generates 100,000 random numbers between 0 and 100, and puts how many times the number between 0 and 100 occours in a list. When it prints out a list, this is what shows:
[0, 947, 2018, 1961, 0, 990, 1994, 0, 934, 0, 0, 976, 0, 0, 967, 1024, 2025, 2009, 2990, 949, 0, 4961, 0, 0, 1037, 951, 1998, 0, 2002, 3076, 0, 0, 0, 2086, 0, 2926, 0, 936, 996, 0, 995, 1010, 0, 0, 1004, 0, 0, 0, 0, 0, 1004, 0, 2909, 1990, 1955, 4833, 0, 1001, 0, 0, 0, 0, 2928, 0, 1976, 1018, 0, 1985, 996, 958, 3005, 0, 1918, 988, 976, 0, 3057, 0, 1010, 988, 0, 1860, 1026, 0, 945, 0, 0, 0, 1988, 999, 1871, 1034, 2976, 1010, 0, 1994, 0, 0, 983, 3026, 1031]
If it was truly random none of the items would be zero occurrences, they would mostly be between 500 and 1500. How can I generate better random numbers?
Aucun commentaire:
Enregistrer un commentaire