Random number generation

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jul 2004
Posts: 1
Reputation: Chris Wong is an unknown quantity at this point 
Solved Threads: 0
Chris Wong Chris Wong is offline Offline
Newbie Poster

Random number generation

 
0
  #1
Jul 25th, 2004
Hi guys,
I'm new in programming and I just started to learn C language. I got this assignment question that requires me to use random number generation. I know how to create a simple random number generation using seed. But this question is giving me a headache. Please spare me some advice.

Write a C program to perform the following task:

Consider P fair dices where each dice is a tetrahedron. The four sides of the i-th dice are numbered 3i, 3i-1, 3i-2, and 0 (blank), respectively, as shown below:

Dice 1: {1, 2, 3, 0}
Dice 2: {4, 5, 6, 0}
Dice 3: {7. 8. 9. 0}
Dice P: {3P-2, 3P-1, 3P, 0}

At each throw, the sum of the numbers on the downward face of each dice is calculated and recorded. By using a random number generator, simulate the result (the faces that have been chosen) for N throws (e.g. 1000000).
From the statistics obtained, determine the number of ways to form all possible sum. For instance, if we try to find the number of combinations with pen and paper, say for P = 4, there are 4 ways to form the sum = 10 as given below:

Dice 1 Dice 2 Dice 3 Dice 4 Sum
0 + 0 + 0 + 10 = 10
1 + 0 + 9 + 0 = 10
2 + 0 + 8 + 0 = 10
3 + 0 + 7 + 0 = 10

Your program should be able to read in 2 variables – i.e. number of throws (N), and number of dices (P). On the output screen, the frequency of getting each sum (Hint: the maximum sum of P dices is 3/2*P*(P+1)), and number of combinations to form the sum (Hint: number of combinations = Freq*(4 power of P)/N) should be displayed. A sample output is given as follows:

Enter number of throws : 1000000
Enter number of dices : 4
Sum : Freq : Number of combinations
0 3933 1
1 3882 1
2 3907 1
3 3895 1
4 3891 1
5 7851 2
6 11712 3
7 15644 4
8 15648 4
9 15682 4
10 15568 4
: : :
: : :
30 3932 1

Hope someone can help with this.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,461
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 254
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Random number generation

 
0
  #2
Jul 25th, 2004
Here is some code that might get you started or give you ideas. You may want to work with it a bit and then post your latest attempt with any remaining questions.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 8
Reputation: .·)Tusky(·. is an unknown quantity at this point 
Solved Threads: 0
.·)Tusky(·.'s Avatar
.·)Tusky(·. .·)Tusky(·. is offline Offline
Newbie Poster

Re: Random number generation

 
0
  #3
Jul 25th, 2004
HAHA, it appears that no one knows how to do this, telling by the amout of replys. LOL . OH WELL

"But I'm not a slave to a god that doesn't exist
But I'm not a slave to world that doesn't give a S•••" - Marilyn Manson (The Fight Song)
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 256
Reputation: FireNet will become famous soon enough FireNet will become famous soon enough 
Solved Threads: 6
FireNet's Avatar
FireNet FireNet is offline Offline
Posting Whiz in Training

Re: Random number generation

 
0
  #4
Jul 26th, 2004
Random Number generation is easy but when you call rand() you only get a number from an array.To get true random numbers you have to seed that array using srand();

call srand(GetTickCount());Then you start getting random numbers.
See what you can, remember what you need

Fourzon | Earn via Coding
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 13395 | Replies: 3
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC