On Mon, Jul 19, 2010 at 04:51, Peter Otten <__pete...@web.de> wrote: > bob gailer wrote: > >> Check this out: >> >> import random, time >> s = time.time() >> cycles = 1000 >> d = "0123456789"*100 >> f = open("numbers.txt", "w") >> for i in xrange(n): >> l = [] >> l.extend(random.sample(d, 1000)) >> f.write(''.join(l)) >> f.close() >> print time.time() - s > > Note that this is not random. E. g. the start sequence "0"*101 should have a > likelyhood of 1/10**101 but is impossible to generate with your setup. I not sure exactly what you mean, because I don't fully understand that '*' (despite Alan's patient explanation), but if you run
import random cycles = 100000 d = "0123456789"*10 for i in range(cycles): l = [] l.extend(random.sample(d, 100)) s = (''.join(l)) if s[:4] == '0101': print(s) You'll see a bunch of strings that begin with "0101" Or if you run import random cycles = 50 d = "0123456789"*10 for i in range(cycles): l = [] l.extend(random.sample(d, 100)) s = (''.join(l)) if s[:1] == '0': print(s) You'll see some that begin with '0'. Am I on the right track? Dick _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor