943,600 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 19004
  • C RSS
Jul 25th, 2004
0

Random number generation

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Chris Wong is offline Offline
1 posts
since Jul 2004
Jul 25th, 2004
0

Re: Random number generation

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.
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Jul 25th, 2004
0

Re: Random number generation

HAHA, it appears that no one knows how to do this, telling by the amout of replys. LOL . OH WELL
Reputation Points: 10
Solved Threads: 0
Newbie Poster
.·)Tusky(·. is offline Offline
8 posts
since Jul 2004
Jul 26th, 2004
0

Re: Random number generation

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.
Reputation Points: 108
Solved Threads: 7
Posting Whiz in Training
FireNet is offline Offline
256 posts
since May 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: use of "find" in the algorithm function
Next Thread in C Forum Timeline: Output in Text file-How to apply fprintf()?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC