On Sat, Jul 17, 2010 at 15:07, Hugo Arts <hugo.yo...@gmail.com> wrote: > On Sat, Jul 17, 2010 at 11:48 PM, Richard D. Moores <rdmoo...@gmail.com> > wrote: >> On Sat, Jul 17, 2010 at 13:56, Dave Angel <da...@ieee.org> wrote: >>> Your concern over a leading zero applies equally to two leading zeroes, or >>> three, or whatever. >> >> I don't think so. Look again at my function, randIntOfGivenLength(). >> Try a for loop with it, say with randIntOfGivenLength(9) and looping >> 100 times: >> >> for x in range(100): >> n = randIntOfGivenLength(9) >> n = str(n) >> print(n) >> >> You'll see that all strings have 9 digits. The problem is that none of >> them begin with "0". These are just strings of almost-random digits, >> and in the script I give the 1st digit a chance to be a "0" by >> prepending a digit -- just one -- chosen by random.choice() from the >> string "0123456789". >> > > This is great, but now your *second* digit will never be zero. So your > strings are still "almost" random.
Aw, you're right. Just as I was feeling pretty good about myself. > <rant> Look, randomness is complicated. It's crap like this that trips > up even cryptographers all the time. I know you won't need your digits > for security or anything, but if you're concerned that the first digit > of a sequence is never zero, you should be equally concerned by the > second digit not being zero. It's the same amount of non-randomness, > and your 'solution' just moves the problem around, it doesn't solve > anything. </rant> > > Hugo > > P.S.: I just thought of this: how about generating numbers that are > one digit too long, and removing the first digit instead of adding an > extra one? It just gets rid of the digit exhibiting non-randomness > altogether. (disclaimer: IANA cryptanalyst, so there may be equally > many things wrong with this) Looks good to me. I'll do it. And post back. Thanks, Hugo. Dick _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor