Well, the internet isn't much of a help, since it doesn't really give any indication how to, or if it's even possible, and in a few cases it just assigned a variable named randMax, but...
I actually just want to know how to set a maximum value for a pseudo-random number generator. I'm working through Stroustrup's book, and on chapter 10 we're exploring fstreams, and he has a struct for reading hours and temperatures. Well, I want something to simply give realistic values, and 32,000 (or more) degrees in any measuring standard is clearly unrealistic.
I know for what it's worth it doesn't matter, but it's still good rand practice, so I wanted to set it between 15-50 degrees for a fair distribution of the current month in Fahrenheit. Thus far all I have is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
#include "../../../StroustrupSupportFiles/std_lib_facilities.h"
struct Reading
{
int hour;
int temperature;
};
int main()
{
cout << "Enter output file: ";
ofstream ofs{ "textout.txt" };
srand(time(0));
int hour;
int temperature = (rand() % 14) + 1;
}
|
Where the include is just Stroustrup's preconfigured all-purpose header. Also, I'm aware it'll give randomized results whenever it's run, and that's OK, as long as they're within reason. I can write the program to get it into a vector (or just write directly) no problem, but bounding the random generation is where I'm stumped.