Question: Part 1 There is a pair of functions in stdlib.h ( make sure to include it ) that are used for generating pseudo - random
Part
There is a pair of functions in stdlib.h make sure to include it that are used for generating pseudorandom numbers. These are "srand" and "rand". Examples are on pages and Note: Functions "srandom" and "random" should be used instead of "srand" and "rand", respectively, since they are more secure Eg function "srand provides the seed value of to the srand function. is just a number, and probably isn't even a good number for this purpose, but that's a discussion for another time The reason that we use a seed value is so that we can reproduce the series of random numbers. Thus, we call them pseudorandom numbers. Being able to reproduce them is important to verify and debug code.
Write a C program to generate a set of random numbers for a given seed value call it labpartc Prompt the user for the seed value, or to quit. Then print random values. When you run your program, try a few different seed values, then try one that you've already tried. Verify that you get the same sequence.
Part
Copy the labpartc program to a new file, labpartc to use in this part.
We will generate random values, but they should be limited to or To do this, think of a way to map the random value to a small value; there are many ways to do this, however, the way you choose must be reproducible. That is if it maps value X to the value it should do that every time the value is X Create a function that accomplishes random number generation and mapping: the function should return a single integer that is a random value of or It does not need any inputs. To verify that it works, have your program print about from it If your program gives you values like or you know you have a problem. Also, if it never generates one of the values or then there is a problem.
Then create an array of ints. Initialize that array to values.
Here is an example of how to create an array called "myarray" of values:
int myarray;
You should call your array something better than "myarray".
Have your program prompt the user for an integer number, read it in then generate that many random values. The generated values are limited to or but the number generated can be much larger. Do not show the random values. Instead, count them, ie every time the function produces a the integer at array position should be incremented. Once all the random numbers have been processed, display the counts. Verify that the numbers make sense; if your program says that there were zero values, ones, twos, and threes, but it was supposed to generate values, you know there is a problem because not Also have your program report the percentages as well as the counts. The percentages should be shown with one digit after the decimal, and they should add up to neglecting any roundoff error
Test your program a few times, and note the relative number of each generated value. Assuming an even distribution, you would see the same counts for each value, ie would be generated of the time, would be of the time, etc. The more values the program generates, the closer to each one should be
Prepare the log like you normally do: use "cat" to show the C programs, use gcc to compile them, and show that the programs run.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
