954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

pseudorandom number generator

I'm making a dice program that calculates the statistics such as actual percentage, expected rolls and expected percentage and so on. I'm having a difficulty on the Pseudo random number generation. With two dice, the mim. sum of the dice is 2, not 1. There is something wrong with my code so it keep generating the number 1 out.

Can anyone help me with that?

cout << "Enter seed: "; 
		cin >> seed; 
		 
		cout << "Number of repeats: "; 
		cin >> intRepeats;  
		 
		x = seed;   //x is the PRN, and the first is user selected  
		 
		for (int i = 0; i < intRepeats; i++) 
		{ 
			x = ((multiplies * x) + inciement) % modulus;    //CREATE A RANDOM NUMBER  
			num = x / float (modulus);  
			roll = int (num * 12) +1; 
		 
			cout << "Dice roll was: " << roll << endl; 
			
			test++;
			frequency[(roll)]++;

[img] http://images.plurk.com/41fc82bc186ee5987fdfd4fcc78bc837.jpg [/img]

chuyauchi
Newbie Poster
24 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

Two possibilities.
A. roll=int(num*11)+2; //Just reduce the 12 to 11 and add 2 instead of 1.
B. rewrite it to roll a single die, save the value, then roll again.

DeanMSands3
Junior Poster
187 posts since Jan 2012
Reputation Points: 37
Solved Threads: 27
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You