The revolutionary project management tool is here! Plan visually with a single glance and make sure your projects get done.

Gwenforweb helped me earlier (here), she gave me a code snippets for 32bit integers. It solved my problem and work perfectly, but as Gwenforweb mentioned, __the snippet was for 32 bit integers__.

My specs changed, now I need 64bit. Can someone__alter her snippets to work using 64-bit integers__?

My specs changed, now I need 64bit. Can someone

```
seed=15239;
for (i=0;i<1000;i++){
seed =(86028157*seed + 142501)%1299689;
rand=seed/1299689;
print(rand);
}
```

http://dl.acm.org/citation.cfm?id=63042

http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.99.6553&rep=rep1&type=pdf

http://www.ics.uci.edu/~smyth/courses/ics178/random_number_generators_article.pdf

seed = (a*seed +c) mod m

Then the random numbers generated will have a full period for all seed values if and only if

c and m are relatively prime,

a - 1 is divisible by all prime factors of m,

a - 1 is a multiple of 4 if m is a multiple of 4

The scheme

seed =(86028157*seed + 142501)%1299689;

satisfies these conditions and is the one I have given you.

Products that use generators of this form and are easily applicable to 64 bits include:-

Numerical Recipes:-

seed = (1664525 *seed +1013904223) mod 2Â³Â²

Older versions of Visual Basic:-

seed = (1140671485*seed +12820163) mod 2^24

Vax's MTH$RANDOM from glibc:-

seed = (69069*seed + 1) mod 2Â³Â²

(a=0 satisfies the full period requirement)

You may also want to avoid correlations between numbers separated by lags

http://www.ncbi.nlm.nih.gov/pmc/articles/PMC285899/pdf/pnas00123-0038.pdf

or small periods in the low order bits.

These simple linear congruence schemes are know to be a bit of an art form and most of the literature on the subject gives values that are know to work well from experience and testing. The three other schemes I have given are from professional products that clearly have proven their worth, and are easily implemented without bit operations.

If the questioner wants a professional high end simulation standard random generator, then we can have a discussion on that as well. But my guess is the generators been given here are of the form the OP is looking for. These still are really really good generators even if they are not world class.

When answering a question I feel it is important to pay attention to what the OP wants and gauge what level they are operating at; and as such respond with mathematics and discussion that is not unnecessary or confusing.

Perhaps the full period generator with a=1, c=1 would suffice.

Perhaps duplicating a particular professional product is desireable. (although some professional products have had notoriously poor PRNG qualities)

Or the full period generators with a=86028157 c=142501 m=1299689

or a=5171 c=142501 m=34421satisfy the requirement of working using 64 bit integers,

so if those didn't satisfy the changed specs, it seems at least conceivable that improved spectral properties could be a consideration.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.

18446744073709551615

ie about 1.8E19

You want to make sure your numbers does not exceed this.

48205429 and 6607882123 are both primes so this should work nicely. And will do for signed integers as well.

seed=15239;

for (i=0;i<1000;i++){

seed =(6607882123 *seed + 142501)%48205429;

rand=seed/48205429;

print(rand);

}