| | |
Random number generation
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jul 2004
Posts: 1
Reputation:
Solved Threads: 0
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.
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.
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
![]() |
Similar Threads
- C++ Random Number Generator (C++)
- Random number generation (Java)
- Random number Generation (C)
- help with this assigment please..it's ARGENT..! (C++)
- Logic behind generating random number (C)
Other Threads in the C Forum
- Previous Thread: use of "find" in the algorithm function
- Next Thread: 2d array
Views: 13395 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for C
#include adobe ansi api array arrays asterisks binarysearch calculate centimeter char command convert copyimagefile cprogramme creafecopyofanytypeoffileinc csyntax directory dynamic fflush file fork forloop framework frequency functions getlasterror givemetehcodez grade graphics gtkgcurlcompiling hacking hardware highest homework inches incrementoperators kernel km lazy linked linkedlist linux linuxsegmentationfault list lists locate logical_drives looping loopinsideloop. match matrix microsoft motherboard multi mysql number opendocumentformat opensource owf pattern pdf performance pointer posix problem probleminc process program programming radix recursion recv repetition research scanf scheduling scripting segmentationfault sequential shape socket socketprograming spoonfeeding stack standard string strings structures student systemcall threads turboc unix user variable voidmain() wab win32 windows.h






