Question: C++: Description: For many of the projects we will do this semester, we will need a way to generate pseudorandom numbers and arrays of random

C++: Description: For many of the projects we will do this semester, we will need a way to generate pseudorandom numbers and arrays of random numbers. To support this, we will create a random number class called MyRandom. The random number class will need: . . Four "constants (integers) and one variable called seed (integer) as member data Two constructors - one with no parameters and one with a single integer parameter A function called RanNum that takes no parameters and returns a double A function called RanRange that takes two integer parameters and returns an integer The four "constants and the two functions should be programmed following the algorithm and cquations on pages 404-5 of the textbook (in Appendix B). (Note: you need to make sure the return statement does not do integer division). The constructor with no parameters should set the seed to INT MAX/2 and the constructor with one parameter should set the seed to the value of the parameter. You will need to include limits.h to be able to use INT_MAX. Once you have written the class, you should write a separate main program to use it. In your main program, create an array of 10 doubles and fill it will numbers from your random number generator. Next, create an array of 10 integers and fill it with the numbers from 1 to 10 in a random order using method 3 on pages 406-7 of the textbook. (Note 1: the book uses (location mod N) + 1 because the book has arrays start at 1. Because C++ has arrays starting at 0, you will need to change this calculation to (location + 1) mod N. This sort of adjustment will be needed for a number of the projects this semester.) You should then print out the values in the two arrays. Be sure to print these in a way that makes it easy to see your results. Note 2: Please create a makefile to handle compilation of your program. As the number of files increases, it is the most efficient way to handle compilation and creation of an executable file. Knowing how to set these up will be very useful for future project assignments. Background comment: These are called pseudorandom numbers because they are not truly random. If you run your program multiple times, you will always get the same answer. If you want to get different answers, one way would be to ask the user to enter an integer and use that for the seed value. Another way that is sometimes used is to get the time from the system clock and use that for the initial seed. You do not need to do that as part of this semester and, therefore, you will not need the constructor with the integer parameter.

C++: Description: For many of the projects we will do this semester,we will need a way to generate pseudorandom numbers and arrays of

random numbers. To support this, we will create a random number class

B.1 GENERATING NUMBERS IN A DIFFERENT RANGE Frequently, an application of random numbers will need values in a range different from that generated by RanNum( ). If we need a value in the range Low SN 0 do location = (location mod N) + 1 if theList[location] = 0 then skip = skip - 1 end if end while theList[location] = i freeCount = freeCount - 1 end for In this algorithm, we use how many cells are free, and generate a random number up to that value. This is done so that we don't have to loop though the list more than one time. You should see that the while loop will always end, because even in the last case, there will be at least one empty location. Description: For many of the projects we will do this semester, we will need a way to generate pseudorandom numbers and arrays of random numbers. To support this, we will create a random number class called MyRandom. The random number class will need: . . Four "constants (integers) and one variable called seed (integer) as member data Two constructors - one with no parameters and one with a single integer parameter A function called RanNum that takes no parameters and returns a double A function called RanRange that takes two integer parameters and returns an integer The four "constants and the two functions should be programmed following the algorithm and cquations on pages 404-5 of the textbook (in Appendix B). (Note: you need to make sure the return statement does not do integer division). The constructor with no parameters should set the seed to INT MAX/2 and the constructor with one parameter should set the seed to the value of the parameter. You will need to include limits.h to be able to use INT_MAX. Once you have written the class, you should write a separate main program to use it. In your main program, create an array of 10 doubles and fill it will numbers from your random number generator. Next, create an array of 10 integers and fill it with the numbers from 1 to 10 in a random order using method 3 on pages 406-7 of the textbook. (Note 1: the book uses (location mod N) + 1 because the book has arrays start at 1. Because C++ has arrays starting at 0, you will need to change this calculation to (location + 1) mod N. This sort of adjustment will be needed for a number of the projects this semester.) You should then print out the values in the two arrays. Be sure to print these in a way that makes it easy to see your results. Note 2: Please create a makefile to handle compilation of your program. As the number of files increases, it is the most efficient way to handle compilation and creation of an executable file. Knowing how to set these up will be very useful for future project assignments. Background comment: These are called pseudorandom numbers because they are not truly random. If you run your program multiple times, you will always get the same answer. If you want to get different answers, one way would be to ask the user to enter an integer and use that for the seed value. Another way that is sometimes used is to get the time from the system clock and use that for the initial seed. You do not need to do that as part of this semester and, therefore, you will not need the constructor with the integer parameter. B.1 GENERATING NUMBERS IN A DIFFERENT RANGE Frequently, an application of random numbers will need values in a range different from that generated by RanNum( ). If we need a value in the range Low SN 0 do location = (location mod N) + 1 if theList[location] = 0 then skip = skip - 1 end if end while theList[location] = i freeCount = freeCount - 1 end for In this algorithm, we use how many cells are free, and generate a random number up to that value. This is done so that we don't have to loop though the list more than one time. You should see that the while loop will always end, because even in the last case, there will be at least one empty location. Description: For many of the projects we will do this semester, we will need a way to generate pseudorandom numbers and arrays of random numbers. To support this, we will create a random number class called MyRandom. The random number class will need: . . Four "constants (integers) and one variable called seed (integer) as member data Two constructors - one with no parameters and one with a single integer parameter A function called RanNum that takes no parameters and returns a double A function called RanRange that takes two integer parameters and returns an integer The four "constants and the two functions should be programmed following the algorithm and cquations on pages 404-5 of the textbook (in Appendix B). (Note: you need to make sure the return statement does not do integer division). The constructor with no parameters should set the seed to INT MAX/2 and the constructor with one parameter should set the seed to the value of the parameter. You will need to include limits.h to be able to use INT_MAX. Once you have written the class, you should write a separate main program to use it. In your main program, create an array of 10 doubles and fill it will numbers from your random number generator. Next, create an array of 10 integers and fill it with the numbers from 1 to 10 in a random order using method 3 on pages 406-7 of the textbook. (Note 1: the book uses (location mod N) + 1 because the book has arrays start at 1. Because C++ has arrays starting at 0, you will need to change this calculation to (location + 1) mod N. This sort of adjustment will be needed for a number of the projects this semester.) You should then print out the values in the two arrays. Be sure to print these in a way that makes it easy to see your results. Note 2: Please create a makefile to handle compilation of your program. As the number of files increases, it is the most efficient way to handle compilation and creation of an executable file. Knowing how to set these up will be very useful for future project assignments. Background comment: These are called pseudorandom numbers because they are not truly random. If you run your program multiple times, you will always get the same answer. If you want to get different answers, one way would be to ask the user to enter an integer and use that for the seed value. Another way that is sometimes used is to get the time from the system clock and use that for the initial seed. You do not need to do that as part of this semester and, therefore, you will not need the constructor with the integer parameter

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!