I just finished up my course in C#. I got a B in the course because I could not complete the following assignment:
We are going to see how uniform the random number generator is for .NET. You will first build a .NET pseudorandom number generator using the following code:
Random r = new Random();
To generate a random number between 0 and 24, use this code:
r.Next(25);
We will be taking a histogram of the values generated by the random number generator. To do this, build an array of 25 integer values, and make sure they are all equal to zero.
Then, in a loop that runs a lot of times, like at least 1000, generate a random number:
int index = r.Next(25);
This integer named index then becomes the index of the integer in your array that you will increment. In other words, by using an array of 25 values indexed 0-24, you are keeping 25 separate counters of occurrences of the index number.
After you have collected your data, print out the counts that you got. The numbers should be pretty close to one another in value. Or, if you want to show off, use the star printing technique we learned in class to print out a sideways graph, like this:
0: ********************* (4 %)
1: ********************* (4 %)
2: ********************** (5 %)
3: ********************* (3 %)
and so on.
OK. Here is my question. This has frustrated me for about 2 weeks now, and even though the course is over, I still want to know how to do this. I missed two classes due to a death in the family and I never fully caught up with the rest of the class. Could someone please show me the solution and give me some explanation of how the code works? All I have completed so for is getting the program to produce the random arrays.