 }
 
 // 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


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

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


	unsigned maxbytes = devProp.totalGlobalMem;
	//because we need 3 arrays (h_x, h_y, h_inside)
	unsigned max_samples = maxbytes / (sizeof(int) + sizeof(curandState));
	// Does GPU support sample size?
	int n = 2e6;
	if (n > max_samples) {
		n = max_samples;
	}
