Timeline for Secure random number generator
Current License: CC BY-SA 3.0
18 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Nov 23, 2014 at 20:25 | comment | added | Nicolas Bouvrette | Awesome, thanks for the edit - for some reasons I didn't get this was split from the main code... must have been tired this morning. I also added an iterator checker on my final version so that if it loops 1,000,000 time, it will write an error to the logs to ease troubleshooting. I doubt this will ever happen but just in case. Thanks again | |
Nov 23, 2014 at 15:00 | comment | added | Nicolas Bouvrette | Not sure I'm picturing it right now but by all means if you want to show me :) | |
Nov 23, 2014 at 14:57 | history | edited | Xenos | CC BY-SA 3.0 |
added 137 characters in body
|
Nov 23, 2014 at 14:55 | comment | added | Xenos |
Welcome ☺ You could make it even a bit faster by extracting $M, $N, $h out of the do...while loop.
|
|
Nov 23, 2014 at 14:51 | comment | added | Nicolas Bouvrette | Well done! Everything works perfectly. I'll use the second option for sure now that I know that its faster. I owe you one... let me know if you need any help with anything! | |
Nov 23, 2014 at 14:44 | comment | added | Xenos |
Messy day ! $N = bcadd($max-$min, 1) : there were an undesired +1 . There should be no difference from the outside. The only difference is that first requires bc* functions, when 2nd don't. BC Math extension is slower than native int calculus.
|
|
Nov 23, 2014 at 14:41 | history | edited | Xenos | CC BY-SA 3.0 |
deleted 2 characters in body
|
Nov 23, 2014 at 14:40 | comment | added | Nicolas Bouvrette | Very cool work... much appreciated! By the way your last update returns value from [$min, $max+1]. This seems to solve it though but I'm sure you got a nicer implementation in mind: return bcmod($r, ($max - $min + 1)) + $min; Also I'm not sure, but what is the main different between the two versions? | |
Nov 23, 2014 at 14:37 | vote | accept | Nicolas Bouvrette | ||
Nov 23, 2014 at 14:31 | comment | added | Xenos |
You're right, I've focused on the proba and forgot to map each [KN..(K+1)N[ to [0..N-1] (iow, the return ). Your fix is OK for 2nd code, use bcmod for first one since $N (the $max - $min +1 ) can be grater than 0x7fffffff .
|
|
Nov 23, 2014 at 14:30 | history | edited | Xenos | CC BY-SA 3.0 |
adding the correct return
|
Nov 23, 2014 at 14:00 | comment | added | Nicolas Bouvrette | I managed to fix it using return $r %($max - $min + 1)+ $min; But I'm not sure this is the best approach? | |
Nov 23, 2014 at 13:33 | comment | added | Nicolas Bouvrette | Ok I have no idea how to repair this.. I will most likely need your help to fix the $min / $max situation because all I can think of it add the modulo at the end but that would defeat the purpose of your fix :) | |
Nov 23, 2014 at 13:25 | comment | added | Nicolas Bouvrette | Wow awesome - I just tested it and the $min / $max seems to have no impact on the return value. I'll see if I figure out why but it does look equiprobable | |
Nov 23, 2014 at 12:05 | history | edited | Xenos | CC BY-SA 3.0 |
Adding (int) cast; adding bc* less version
|
Nov 23, 2014 at 11:52 | history | edited | Xenos | CC BY-SA 3.0 |
Adding (int) cast; adding bc* less version
|
Nov 23, 2014 at 11:48 | review | First posts | |||
Nov 23, 2014 at 14:26 | |||||
Nov 23, 2014 at 11:46 | history | answered | Xenos | CC BY-SA 3.0 |