title: curand gives the same number every time in a thread
body: <p>When I call curand, I always get the same number in a thread. They are different for each thread however. What am I doing wrong in the next code?</p>
  
  <pre><code>#define MAXTHREADS 2
  #define NBBLOCKS 2
  
  
  __global__ void testRand ( curandState * state, int nb ){
      int id = threadIdx.x  + blockIdx.x * blockDim.x;
      int value;
      for (int i=0;i&lt;nb;i++){
          curandState localState = state[id];
          value = curand(&amp;localState);
          printf("Id %i, value %i\n",id,value);
      }
  }
  __global__ void setup_kernel ( curandState * state, unsigned long seed )
  {
      int id = threadIdx.x  + blockIdx.x * blockDim.x;
      curand_init ( seed, id , 0, &amp;state[id] );
  }
  
  /**
  * Image comes in in horizontal lines
  */
  void findOptimum() {
      const dim3 blockSize(MAXTHREADS);
      const dim3 gridSize(NBBLOCKS);
  
      curandState* devStates;
      cudaMalloc ( &amp;devStates,MAXTHREADS*NBBLOCKS*sizeof( curandState ) );
      time_t t;
      time(&amp;t);
      setup_kernel &lt;&lt;&lt; gridSize, blockSize &gt;&gt;&gt; ( devStates, (unsigned long) t );  
      int nb = 4;
      testRand  &lt;&lt;&lt; gridSize, blockSize &gt;&gt;&gt; ( devStates,nb);  
      testRand  &lt;&lt;&lt; gridSize, blockSize &gt;&gt;&gt; ( devStates,nb);  
  
      cudaFree(devStates);
  }
  </code></pre>
  
  <p>It outputs:</p>
  
  <pre><code>Id 0, value -1075808309
  Id 1, value -1660353324
  Id 2, value 1282291714
  Id 3, value -1892750252
  Id 0, value -1075808309
  Id 1, value -1660353324
  Id 2, value 1282291714
  Id 3, value -1892750252
  ...
  </code></pre>
  
  <p>This repeats a few times more.</p>