1 2 3 4 5 6 7 8
#!/usr/bin/env python2 import numpy as np n=10000.0 s=100.0 print "should be ~ %d: %d"%(int(s),len([x for x in (np.random.uniform(0,1,int(n)) >= (1-(s/n))) if x]))