1139823Simp/* 2133578Sharti * Xorshift Pseudo Random Number Generator based on work by David Blackman 3133578Sharti * and Sebastiano Vigna (vigna@acm.org). 4133578Sharti * 5133578Sharti * "Further scramblings of Marsaglia's xorshift generators" 6133578Sharti * http://vigna.di.unimi.it/ftp/papers/xorshiftplus.pdf 7133578Sharti * http://prng.di.unimi.it/xoroshiro128plusplus.c 8133578Sharti * 9133578Sharti * To the extent possible under law, the author has dedicated all copyright 10133578Sharti * and related and neighboring rights to this software to the public domain 11133578Sharti * worldwide. This software is distributed without any warranty. 12133578Sharti * 13133578Sharti * See <http://creativecommons.org/publicdomain/zero/1.0/>. 14133578Sharti * 15133578Sharti * This is xoroshiro128++ 1.0, one of our all-purpose, rock-solid, 16133578Sharti * small-state generators. It is extremely (sub-ns) fast and it passes all 17133578Sharti * tests we are aware of, but its state space is large enough only for 18133578Sharti * mild parallelism. 19133578Sharti */ 20133578Sharti 21133578Sharti#include <sys/vdev_draid.h> 22133578Sharti 23133578Shartistatic inline uint64_t rotl(const uint64_t x, int k) 24133578Sharti{ 25133578Sharti return (x << k) | (x >> (64 - k)); 26133578Sharti} 27133578Sharti 28133578Shartiuint64_t 29133578Shartivdev_draid_rand(uint64_t *s) 30133578Sharti{ 31133578Sharti const uint64_t s0 = s[0]; 32133578Sharti uint64_t s1 = s[1]; 33133578Sharti const uint64_t result = rotl(s0 + s1, 17) + s0; 34133578Sharti 35133578Sharti s1 ^= s0; 36133578Sharti s[0] = rotl(s0, 49) ^ s1 ^ (s1 << 21); // a, b 37133578Sharti s[1] = rotl(s1, 28); // c 38133578Sharti 39133578Sharti return (result); 40133578Sharti} 41133578Sharti