added qse_randxs32() and qse_randxs64().

changed awk's rand() to use these.
fixed a bug of registering rand() with a wrong number of arguments in StdAwk.
This commit is contained in:
2012-08-27 15:10:57 +00:00
parent 53c98cce93
commit a35c10fbfc
4 changed files with 114 additions and 36 deletions

View File

@ -41,3 +41,43 @@ qse_uint32_t qse_rand31 (qse_uint32_t seed)
return lo;
}
/*
* Xorshift RNGs by George Marsaglia, The Florida State University
* http://www.jstatsoft.org/v08/i14/paper
*/
#if (QSE_SIZEOF_UINT32_T > 0)
qse_uint32_t qse_randxs32 (qse_uint32_t seed)
{
qse_uint32_t x;
QSE_ASSERT (seed != 0);
x = seed;
x ^= (x << 13);
x ^= (x >> 17);
x ^= (x << 5);
return x;
}
#endif
#if (QSE_SIZEOF_UINT64_T > 0)
qse_uint64_t qse_randxs64 (qse_uint64_t seed)
{
qse_uint64_t x;
QSE_ASSERT (seed != 0);
x = seed;
x ^= (x << 21);
x ^= (x >> 35);
x ^= (x << 4);
return x;
}
#endif