#!/usr/bin/python import random total = 0; good = 0; for n in xrange(1,100000000): i = random.randint(0,99999999) s = "{0:0>8}".format(i); a = {} for c in list(s): if c in a.keys(): a[c]+=1; else: a[c]=1; if 4 in a.values(): good+=1; if n % 100000 == 0: ratio = good/float(n) print "%.4f = %d / %d"%(ratio,good,n)