Hey, this is a code where I generate random variable from a min and max. Right now, I want to fix the limit of the number. Let say, that I want to generate 10 random numbers. I need your help to do this! I try to add :
for(int i=0; i<10; ++i)
{ }
But doesn't work, I don't know where to add it (I’m beginner, I ckecked some forums but ...)
this is the lines :
/* define a function to generate a random number among min_num and max_num*/
double AverageRandom(double min_num,double max_num)
{
double random_num;
double diff_num=max_num-min_num;
random_num=min_num+rand() / (double)(RAND_MAX)*diff_num;
Avoid the C random functions. C++ has better and more random generating features than C.
http://www.cplusplus.com/reference/random/
C++ random number generation uses two separate but related "steps:"
1. random number engine function objects to generate a uniformly distributed sequence of integer values.
2. distribution function objects to generate a sequence of values from supplied min/max values.
The C++ <random> library has multiple engine and distribution objects, not the "one size fits all" limitations that C has.
And finally, PLEASE learn to use "code tags" for your source code, easier to read properly formatted source, and includes "line numbers" for easy reference. You can "go back" and edit to "tag" your source: