+ /* http://en.wikipedia.org/wiki/Xorshift
+ * Moderately good statistical properties:
+ * fails the following "dieharder -g 200 -a" tests:
+ * diehard_operm5| 0
+ * diehard_oqso| 0
+ * diehard_count_1s_byt| 0
+ * diehard_3dsphere| 3
+ * diehard_squeeze| 0
+ * diehard_runs| 0
+ * diehard_runs| 0
+ * diehard_craps| 0
+ * diehard_craps| 0
+ * rgb_minimum_distance| 3
+ * rgb_minimum_distance| 4
+ * rgb_minimum_distance| 5
+ * rgb_permutations| 3
+ * rgb_permutations| 4
+ * rgb_permutations| 5
+ * dab_filltree| 32
+ * dab_filltree| 32
+ * dab_monobit2| 12
+ */
+ again:
+ t = rnd->xs64_x ^ (rnd->xs64_x << a);
+ rnd->xs64_x = rnd->xs64_y;
+ rnd->xs64_y = rnd->xs64_y ^ (rnd->xs64_y >> c) ^ t ^ (t >> b);
+ /*
+ * Period 2^64-1 = 2^32+1 * 2^32-1 has a common divisor with Galois LFSR.
+ * By skipping two possible states (0x1 and 0x2) we reduce period to
+ * 2^64-3 = 13 * 3889 * 364870227143809 which has no common divisors:
+ */
+ if (rnd->xs64_y == 0 && rnd->xs64_x <= 2)
+ goto again;
+
+ /* Combined LCG + Galois LFSR rng has 2^32 * 2^32-1 period.
+ * Strength:
+ * individually, both are extremely weak cryptographycally;
+ * when combined, they fail the following "dieharder -g 200 -a" tests:
+ * diehard_rank_6x8| 0
+ * diehard_oqso| 0
+ * diehard_dna| 0
+ * diehard_count_1s_byt| 0
+ * rgb_bitdist| 2
+ * dab_monobit2| 12
+ *
+ * Combining them with xorshift-64 increases period to
+ * 2^32 * 2^32-1 * 2^64-3
+ * which is about 2^128, or in base 10 ~3.40*10^38.
+ * Strength of the combination:
+ * passes all "dieharder -g 200 -a" tests.
+ *
+ * Combining with subtraction and addition is just for fun.
+ * It does not add meaningful strength, could use xor operation instead.
+ */
+ t = rnd->galois_LFSR - rnd->LCG + rnd->xs64_y;
+
+ /* bash compat $RANDOM range: */
+ return t & RAND_BASH_MASK;