PRNG proposal
Matthew Woehlke
mw_triad at users.sourceforge.net
Fri Dec 12 00:31:44 CET 2008
Ok, after fiddling more with integer-only algorithms, here's something
that isn't *too* horribly many operations, that's non-recursive and only
uses only integers. It seems to look okay*, but hasn't been tested for
any sort of distribution theory.
quint64 myRand48(quint64 n, quint64 a, quint64 b)
{
return ((n * a) + b); // needed?? & 0xFFFFFFFFFFFF;
}
quint64 myRandom(int x, int y, int seed)
{
quint64 n = (quint64(x) * 1103515249) + (quint64(y) * 91573268041)
+ seed;
n = myRand48(n, 8759824322359, 13);
n = (n >> 24) ^ (n << 24);
n = myRand48(n, 200560490131, 2707);
n ^= x ^ (y * 39916801);
return myRand48(n, 26329792769470687, 62017);
}
(* the lower several bits are still obviously patterned. As long as the
upper ~40 bits are favored this should be ok, but taking the result
&0xFF won't work well.)
I won't feel hurt if y'all don't like this. I'd be *thrilled* if anyone
can improve it :-). It's just something that /might/ (and I do stress
"might") be usable as a pure-integer algorithm.
(In its favor - though I think this is true of the current algorithm
also - it achieves one of my goals, which is that changing the seed
completely changes the output.)
--
Matthew
Please do not quote my e-mail address unobfuscated in message bodies.
--
|-\ /-\ \ | -+- |-\ + \ | -+- /-\
| | | | |\| | |-/ /-\ |\| | |
|-/ \-/ | \ | | | | | \ -+- \-/
More information about the kimageshop
mailing list