dimanche 29 novembre 2020

Why do we XOR with 4101842887655102017 while implementing Ranq1 in Numerical Recipes (c++)?

Good afternoon everyone. I am reading through the Numerical Recipes book (Edition 3) by William H. Press, Saul A. Teukolsky, William T. Vetterling.

On the page 351 the example of the composed random number generator is given. I can understand all code line by line, yet I hardly can comprehend why there is XOR operation between v^j. Could anyone explain why do we do the XOR between the seed and v?

struct Ranq1 {
Ullong v; //the long long 64-bit variable (typedef)
Ranq1(Ullong j): v(4101842887655102017LL) {
    v^=j; 
    v = int64();
}
//Xorshift algorithm to generate uniform random numbers with 
inline Ullong int64() {
    v ^= v >> 21;
    v ^= v <<35;
    v ^= v >> 4; 
    return v * 2685821657736338717LL; //d1

}
};

Will be grateful for any ideas and help!




Aucun commentaire:

Enregistrer un commentaire