lundi 12 septembre 2016

Different random numbers with curand XORWOW random number generator with original published version of the xorwow algorithm?

This is the code for xorwow random number generator which I got from George Marsaglia. Xorshift RNGs. Journal of Statistical Software, 8(14), 2003. Available at http://ift.tt/LPnViB

uint32_t xorwow() {
  static uint64_t  x = 123456789, y = 362436069, z = 521288629,
                   w = 88675123, v = 5783321, d = 6615241;
  uint64_t;
  t = (x ^ (x >> 2));
  x = y;
  y = z;
  z = w;
  w = v;
  v = (v ^ (v << 4)) ^ (t ^ (t << 1));
  return (d += 362437) + v;
}
//Marsaglia's paper uses unsigned long as the word type. This has been changed to uint32_t to ensure the word type is an unsigned 32-bit integer.

Output:
246875399  3690007200  1264581005  3906711041  1866187943  2481925219       2464530826  2677782455  3653403911  2504343560

But when I execute below example code from curand api from http://ift.tt/2cD4jyb

/*  This program uses the host CURAND API to generate 10  pseudorandom ints. */

int main(int argc, char *argv[]) {
  size_t n = 10;
  size_t i;
  curandGenerator_t gen;
  unsigned int *devData, *hostData; /* Allocate n ints on host */

  hostData =
    (unsigned int *)calloc(n, sizeof(unsigned int)); /* Allocate n ints on */

  CUDA_CALL(cudaMalloc(
    (void **)&devData,
    n * sizeof(unsigned int))); /* Create pseudo-random number generator */

  CURAND_CALL(
    curandCreateGenerator(&gen, CURAND_RNG_PSEUDO_XORWOW)); /* Set seed */

  CURAND_CALL(curandSetPseudoRandomGeneratorSeed(
gen, 0)); /* Generate n ints on device */

  CURAND_CALL(curandGenerate(gen, devData,
                                  n)); /* Copy device memory to host */
  CUDA_CALL(cudaMemcpy(hostData, devData, n * sizeof(int),
                     cudaMemcpyDeviceToHost)); /* Show result */
  for (i = 0; i < n; i++) {
    printf("%u ", hostData[i]);
  }

output : 3179217846 3955638199 167591721 4161663997 3973448494   1917059131 2866113984 472148682 2019573489 2204150021 

Both are from same paper but I got a different answer! Could anybody help me in this ? Thanks in advance !

As always, I apologize if someone has asked this and it's been answered elsewhere. I did search and couldn't find what I needed.




Aucun commentaire:

Enregistrer un commentaire