#include "Random.h" #include /* rand() is not fast, or random, or the same across systems. So here is RANROT-B PRNG. */ static int low = 0, high = ~0; #define FIRST_RUN_ITERATIONS 50 void sdrand(int seed) { int iteration; low = seed; high = ~seed; for (iteration = 0; iteration < FIRST_RUN_ITERATIONS; iteration++) { irand(); } } unsigned int uirand() { high = ((high << 16) + (high >> 16)); high += low; low += high; return (high & INT_MAX); } int irand() { high = ((high << 16) + (high >> 16)); high += low; low += high; return high; } float ufrand(float range) { return ((range * uirand()) / (float) INT_MAX); } float frand(float range) { return ((range * irand()) / (float) INT_MAX); }