I'm working with a simulation that needs random numbers. I've been using macros because they're a little bit faster than rand(). These are the generators that I've been using:
#define SHR3 (jsr^=(jsr<<13), jsr^=(jsr>>17), jsr^=(jsr<<5))
#define CONG (jcong=69069*jcong+1234567)
The problem I'm having is that both of these repeat after about 2^32 which is too often. It causes my simulation to get stuck in weird cycles.
I tried this one:
#define znew (z=36969*(z&0xFFFF)+(z>>16)+1)
#define wnew (w=18000*(w&0xFFFF)+(w>>16)+1)
#define MWC ((znew<<16)+wnew+(z>>16))
It is faster than rand(), though slower than the other two, and it has two 32 bit ints for its state, but it doesn't use the whole state, and it actually repeats much more often than the other two.
So, I want a generator that is fast, implementable in a macro, and with a cycle of about 2^64 (or greater) that works well on a 32 bit processor. It would be ideal if the state were only 64 bits and the generator cycled through every possible value of the state.
Do you know of any generator like that?
Aucun commentaire:
Enregistrer un commentaire