rng.sol 605 B

1234567891011121314151617181920212223
  1. contract rng {
  2. // not a good RNG, just enough 256-bit operations to dominate loop overhead
  3. uint rand;
  4. function test() returns (uint) {
  5. uint rand1 = 3;
  6. uint rand2 = 5;
  7. uint rand3 = 7;
  8. uint rand4 = 11;
  9. for (int i = 0; i < 1000000; ++i) {
  10. rand1 = 0x243F6A8885A308D3 * rand1 + 0x13198A2E03707344;
  11. rand2 = 0xA4093822299F31D0 * rand2 + 0x082EFA98EC4E6C89;
  12. rand3 = 0x452821E638D01377 * rand3 + 0xBE5466CF34E90C6C;
  13. rand4 = 0xC0AC29B7C97C50DD * rand3 + 0x3F84D5B5B5470917;
  14. }
  15. return rand1 ^ rand2 ^ rand3 ^ rand4;
  16. return rand;
  17. }
  18. function rng() {
  19. rand = test();
  20. }
  21. }