To iterate over 100 values and select randomly 0 or 1.But equal number of time
The code below prints the counts:
import random
c_true = 0;c_false = 0
for i in range(100):
a = random.getrandbits(1)
if( a == 1):
c_true += 1
else:
c_false += 1
print "true_count:",c_true
print "false_count:",c_false
The output is:
true_count: 56
false_count: 44
I want the counts to be equal
true_count: 50
false_count: 50
If anyone could suggest the changes to the code to obtain the desired result it will be help ful?
Aucun commentaire:
Enregistrer un commentaire