468,513 Members | 1,763 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,513 developers. It's quick & easy.

Loaded Dice Tester

13
I have this assigment to do that determines which of three dice are loaded. The dice are actually three C functions called dieA(), diaB(), and dieC()each of which returns an int in the range 1 – 6 when called.

I would have to exercise each of the dice functions and determines which one is “loaded.”


This is my idea of how to make ten throws of die A
Expand|Select|Wrap|Line Numbers
  1.  #include 
  2. "threeDice.h" /* header file */
  3. int main()
  4. {
  5. int j;
  6. for ( j=0; j<10; j++ )
  7. printf("%2d\n", dieA() );
I would like to know how I would begin to do this program. I was messing around with the rand() function to replicate the throwing of the dice. I know I need variables for a counter and for the number of rolls.

Any help would be appreciated.
Oct 5 '06 #1
2 3363
r035198x
13,262 8TB
I have this assigment to do that determines which of three dice are loaded. The dice are actually three C functions called dieA(), diaB(), and dieC()each of which returns an int in the range 1 – 6 when called.

I would have to exercise each of the dice functions and determines which one is “loaded.”


This is my idea of how to make ten throws of die A
Expand|Select|Wrap|Line Numbers
  1.  #include 
  2. "threeDice.h" /* header file */
  3. int main()
  4. {
  5. int j;
  6. for ( j=0; j<10; j++ )
  7. printf("%2d\n", dieA() );
I would like to know how I would begin to do this program. I was messing around with the rand() function to replicate the throwing of the dice. I know I need variables for a counter and for the number of rolls.

Any help would be appreciated.
You could design it this way.
Each method uses a different method for generating random numbers(So perhaps you need three different random functions, or try to manipulate the seeds to the calls to the rand() function)

generate say n throws of the die with each of the functions.
you could use three arrays. array a for storing numbers from method dieA(), array b for etc.

Then you need a test for randomness of the numbers runs test etc (whatever is not complicated for you).

so you then just take the values in each of the arrays and test them for randomness. A good test will give you the degree of randomness for each test so that you can say which method produced the least random numbers.

The greater the size of a, the more consistent your results become.
Oct 5 '06 #2
DeFault
13
Please forgive the errors in code I just wanted to get it written down to understand it. If there is anything that I have missed could please explain what it is.

Expand|Select|Wrap|Line Numbers
  1. int dieA();
  2. int dieB();
  3. int dieC();
  4.  
  5. #include <stdio.h>
  6. #include "threeDice.h"
  7.  
  8. int main ()
  9. {
  10.     int a_store[0];
  11.     int b_store[0];
  12.     int c_store[0];
  13.     int n_throws, size;
  14.     int a_random;
  15.  
  16.     for ( n_throws = 0; n_throws < size; n_throws++){
  17.  
  18.         printf ("%2d\n", dieA());
  19.         a_store[n_throws];
  20.  
  21. }
  22.  
  23. for ( n_throws = 0; n_throws < size; n_throws++){
  24.  
  25.         printf ("%2d\n", dieB());
  26.         b_store[n_throws];
  27.         }        
  28.  
  29.         for ( n_throws = 0; n_throws < size; n_throws++){
  30.         c_store[n_throws];
  31.         printf ("%2d\n", dieC());
  32.         }
  33.  
  34.        a_random = rand() a_store[n_throws];
  35.  
Oct 6 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Hal Vaughan | last post: by
2 posts views Thread by Michele Simionato | last post: by
11 posts views Thread by Tomi Lindberg | last post: by
101 posts views Thread by Elijah Cardon | last post: by
reply views Thread by Bree | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.