kiss generator

 

http://ceur-ws.org/Vol-2267/568-572-paper-109.pdf

 1 unsigned long long int kiss(std::vector<unsigned long long int>& seed) {
 2 unsigned long long int t;
 3 const unsigned long long int a = 698769069llu;
 4 seed[0] = 69069 * seed[0] + 123456;
 5 seed[1] = seed[1] ^ (seed[1] << 13);
 6 seed[1] = seed[1] ^ (seed[1] >> 17);
 7 seed[1] = seed[1] ^ (seed[1] << 5);
 8 t = a * seed[2] + seed[3];
 9 seed[3] = (t >> 32); seed[2] = t;
10 return seed[0] + seed[1] + seed[2];
11 }

 

seed generate

http://www0.cs.ucl.ac.uk/staff/d.jones/GoodPracticeRNG.pdf

 1 unsigned int devrand(void)
 2 {
 3  int fn;
 4  unsigned int r;
 5  fn = open("/dev/urandom", O_RDONLY);
 6  if (fn == -1)
 7  exit(-1); /* Failed! */
 8  if (read(fn, &r, 4) != 4)
 9 exit(-1); /* Failed! */
10  close(fn);
11  return r;
12 }
13 /* Initialise KISS generator using /dev/urandom */
14 void init_KISS()
15 {
16  x = devrand();
17  while (!(y = devrand())); /* y must not be zero! */
18  z = devrand();
19  /* We don’t really need to set c as well but let's anyway… */
20  /* NOTE: offset c by 1 to avoid z=c=0 */
21  c = devrand() % 698769068 + 1; /* Should be less than 698769069 */
22 }