 }
 
 // RNG init kernel
-__global__ void initRNG(curandState * const rngStates,
+__global__ void initRNG(curandState * const rngStates, int n,
 		const unsigned int seed) {
 	// Determine thread ID
 	unsigned int thread_id = blockIdx.x * blockDim.x + threadIdx.x;
 
-	// Initialise the RNG
-	curand_init(seed, thread_id, 0, &rngStates[thread_id]);
+	if (thread_id < n) {
+		// Initialise the RNG
+		curand_init(seed, thread_id, 0, &rngStates[thread_id]);
+	}
 }
 
 // Compute on Iteration

		blocks.x = divup(blocks.x, blocks.y);
	}

	// Allocate memory for RNG states
	curandState *h_rngStates = 0;
	curandState *d_rngStates = 0;
	checkCuda(
			cudaHostAlloc(&d_rngStates,
					blocks.x * threads.x * sizeof(curandState),
					cudaHostAllocWriteCombined | cudaHostAllocMapped));

	checkCuda(cudaHostGetDevicePointer(&d_rngStates, h_rngStates, 0));

	// Allocate hits array


	printf("Init RNG\n");
	unsigned int seed = (unsigned) time(0);
	initRNG<<<blocks, threads>>>(d_rngStates, n, seed);

	printf("Run computation on GPU\n");
	device_method<<<blocks, threads>>>(d_hits, n, d_rngStates);
