Advertisement
B1KMusic

Decent PRNG algorithm

Oct 8th, 2016
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.47 KB | None | 0 0
  1. // Zero collisions for all input 0 .. 65535
  2. // Does not seem to get stuck in a tight predictable sequence.
  3. // I can't predict nor see a pattern in its output.
  4. // Test cases: http://pastebin.com/Kz7dLGBC
  5.  
  6. #include <stdint.h>
  7.  
  8. uint16_t
  9. get_random_number(uint16_t seed)
  10. {
  11.     uint16_t out = (seed + 1) * (0xacdc + 1);
  12.     return out == seed ? ++out : out;
  13. }
  14.  
  15. // Unlike Munroe's RNG (xkcd.com/221), it's not *guaranteed* to be random, as it wasn't chosen by a fair dice roll
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement