0

Using this C code for reference (sourced from http://en.wikipedia.org/wiki/Xorshift):

uint64_t s[2];
uint64_t xorshift128plus(void) {
    uint64_t x = s[0];
    uint64_t const y = s[1];
    s[0] = y;
    x ^= x << 23; // a
    x ^= x >> 17; // b
    x ^= y ^ (y >> 26); // c
    s[1] = x;
    return x + y;
}

Is the following the equivalent java code in terms of maintaining the randomness properties (other than a different mapping between seeds and return value):

long s[2];
long xorshift128plus(){
    long x = s[0];
    long y = s[1];
    s[0] = y;
    x ^= x << 23; // a
    x ^= x >>> 17; // b
    x ^= y ^ (y >>> 26); // c
    s[1] = x;
    return x + y;
}
lgp
  • 325
  • 4
  • 12
  • 1
    It actually looks *exactly* the same to me. What's the difference? Ignore the signedness of the results, obviously. – harold Feb 10 '15 at 20:32
  • I just wanted confirmation that they are essentially equivalent. – lgp Feb 10 '15 at 20:57
  • The mapping between seeds an return values is the same too. – harold Feb 10 '15 at 21:22
  • Looks the same to me. My implementation is logically identical to yours but to make bytecode shorter my implementation uses 2 longs instead of an array of long and joins lines for "b" and "c" into one. – oᴉɹǝɥɔ May 01 '16 at 17:48

1 Answers1

1

I distribute a complete implementation of PRNGs from the xorshift family in the DSI utilities: http://dsiutils.di.unimi.it/docs/it/unimi/dsi/util/package-summary.html

seba
  • 403
  • 3
  • 12