mercredi 21 août 2019

How can I increase the period of this PRNG?

I found this pseudo random number generator on Wikipedia and gave it a try, it's fast and works great for what I intend to use, but I would like it to have a bigger period, is there a way of improving it without making it slower?

#include <stdio.h>

long seed = 134515345;

long xorshift_rand(){
    seed ^= seed >> 13;
    seed ^= seed << 17;
    seed ^= seed >> 5;
    return seed;
}


int main()
{
    long start = xorshift_rand();
    long n = 0;
    while (start != xorshift_rand()){
        n++;
        if (n == 0){
            printf("overflow, good.");
        }
    }
    printf("xorshift_rand has a period of %ld", n);

    return 0;
}





Aucun commentaire:

Enregistrer un commentaire