stellar

Stellar - Chess engine written in C
Log | Files | Refs

random.c (566B)


      1 #include "random.h"
      2 
      3 U32 state = C32(1804289383);
      4 
      5 void random_state_reset() { state = C32(1804289383); }
      6 
      7 U32 random_get_U32() {
      8     U32 number = state;
      9 
     10     number ^= number << 13;
     11     number ^= number >> 17;
     12     number ^= number << 5;
     13 
     14     return state = number;
     15 }
     16 
     17 U64 random_get_U64() {
     18     U64 n1, n2, n3, n4;
     19 
     20     n1 = (U64)(random_get_U32()) & C64(0xFFFF);
     21     n2 = (U64)(random_get_U32()) & C64(0xFFFF);
     22     n3 = (U64)(random_get_U32()) & C64(0xFFFF);
     23     n4 = (U64)(random_get_U32()) & C64(0xFFFF);
     24 
     25     return n1 | (n2 << 16) | (n3 << 32) | (n4 << 48);
     26 }