Starting from:

$25

Assignment 4:Simulate random events

Assignment 4:
------------ Points: 10
Purpose: Use loops, rand( ) and do some analysis of the
randomness of rand( ).

Description:

Write a program that will simulate the following random
events using the rand( ) function in the C standard
libraries. We are interested in determining if rand( )
really seems to produce a random set of values. To do this
we will repeat the event a certain number of times and see
how often we get each of the possible results. If rand( )
is truly random, and our mapping to the possible results is
uniform, our results should be equally likely and therefore
evenly distributed across all possible results.

The two events will be:
1) Flipping a coin
2) Rolling a six-sided die

Repeat each event:
1) 10
2) 100
3) 1000
4) 10,000
5) 100,000 times

Within each set of repetitions, count how often each result
occurs. Then compute the percentage of the total events
were represented by each result.

Ex:
Coin:
----
Flips: 10 Heads: 40%
Tails: 60%

Die:
----
Rolls: 10 1: 10%
2: 0%
3: 20%
4: 30%
5: 30%
6: 10%

...

Coin:
----
Flips: 100000 Heads: 49%
Tails: 51%

Die:
----
Rolls: 100000 1: 17%
2: 18%
3: 17%
4: 17%
5: 17%
6: 16%



Notes:
-----
- Do not "randomly" seed the rand( ) function, we are
interested in repeatability.
- No inputs are necessary.
- Gradually develop your program in steps

- There is a "Supplement" posted on Otto that discusses
the rand( ) function and there are "Random_.c examples
in the examples directory.

More products