Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a c program that will simulate the following random events using the rand( ) function in the C standard libraries. We are interested in
Write a c 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. We will simulate the following three events: 1) Flipping a coin 2) Rolling a six-sided die 3) Drawing one particular card from a shuffled deck of 52 cards, for example the Ace of Spades 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% Card: ---- Draws: 10 Card wanted: 0% Not card wanted: 100% ... Coin: ---- Flips: 100000 Heads: 49% Tails: 51% Die: ---- Rolls: 100000 1: 17% 2: 18% 3: 17% 4: 17% 5: 17% 6: 16% Card: ---- Draws: 100000 Card wanted: 2% Not card wanted: 98%
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started