Re:Anatomy of a pseudorandom number generator – visualising ...
by jlgreco on Monday July 08, 2013 @11:55PM
(#6011008)
It's not just the errors that were made though. I mean, ignoring the off-by-one error:
I am not sure what sort of code-review process they had in place if someone saw that and thought "Yup, brilliant. Ship it." I am sure we have all written code like that at one point in our lives, but code that is shipping to the general public?
[ Parent
| on HN ]
Re:Anatomy of a pseudorandom number generator – visualising ...
by billforsternz on Tuesday July 09, 2013 @12:53AM
(#6011166)
It's not the most elegant code I've ever seen - but I don't otherwise see a red flag. What's your problem with it ? I don't think the worry that a semi-infinite string of legitimate values >250 is going to come out of randomSalsaByte() is a real, practical problem. You may as well worry that the complete works of Shakespeare asciified might come out of the PRNG. In theory it could happen. In practice, it won't happen even once in 10^100 universe lifetimes. The transistors in the CPU are going to spontaneously fail whilst executing the code zillions of times more often.
Re:Anatomy of a pseudorandom number generator – visualising ...
by axman6 on Tuesday July 09, 2013 @03:22AM
(#6011545)
The issue isn't the potentially infinite loop, it's the fact it creates an uneven distribution of values, giving 0 a 1/250 greater chance of being selected, and thus makes the results of the PRNG more predictable. The article makes this pretty clear...
Re:Anatomy of a pseudorandom number generator – visualising ...
by billforsternz on Tuesday July 09, 2013 @04:43PM
(#6015324)
What part of "ignoring the off by one error" in the parent don't you get ? Edit: Sorry, unnecessarily snarky, and I could have made my (now uneditable) post clearer by saying ">=250" rather than ">250".
Re:Anatomy of a pseudorandom number generator – visualising ...
by mpyne on Tuesday July 09, 2013 @08:29AM
(#6012285)
The article also makes clear that it's a standard fencepost error. Freakishly poor crypto, but not bush-league programming.
Re:Anatomy of a pseudorandom number generator – visualising ...
by mistercow on Tuesday July 09, 2013 @12:49AM
(#6011153)
How else do you generate an unbiased random number between 0 and 250? As far as I know, that's the standard algorithm.
Re:Anatomy of a pseudorandom number generator – visualising ...
by jlgreco on Tuesday July 09, 2013 @01:18AM
(#6011237)
My concern is with why they are doing that in the first place. It is possible that I am missing something here, I haven't looked at their actual code, but it seems to me that this concern would have been entirely avoided if they went with 0-F instead of 0-9.
Re:Anatomy of a pseudorandom number generator – visualising ...
by mistercow on Tuesday July 09, 2013 @01:34AM
(#6011256)
Yes, I definitely agree with that, and I don't understand why they did it that way. Generating a float in the [0,1) range by producing decimal digits seems utterly perverse. The sane, naive, and correct way to do it is to generate an integer between 0 and 2^53 and then divide by 2^53.