[Tutor] What are these things urandom() returns?

Dick Moores rdm at rcblue.com
Tue Oct 10 21:29:26 CEST 2006


Thanks very much, Kent and Alan.

I'm thinking that just for the hell of it I could use urandom() as a 
source of random decimal digits. Or in a coin tossing program. Here's 
a list of 7817 '1's and 0's generated by urandom():

 >>> from os import urandom
 >>> lst = list(urandom(1000000))
 >>> tosses = [y for y in lst if y in '01']
 >>> len(tosses)
7817
 >>>

Would this be a better random source than choice([0,1]), which uses random()?

Dick



More information about the Tutor mailing list