IT is defined in the back of my book but can't be found in my program.

Recommended Answers

All 5 Replies

You haven got anything such as int random(int); .

For generation of random numbers you have got the function rand which is of the format int rand(void); .Defined in cstdlib.You will get more information in this <link>.

but i want it to be between 2 numbers. can i change rand_max number?

would i have to overload the function?

Or a brute force approach would be something like this :

int total;//this holds the number of random numbers to be generated
//Assume you want to generate random numbers between 50 and 70
int cnt=0;//This hold the number of random numbers already generated.
while(cnt<total)
{
//Generate the random number between 1 and 70 say number is rnum
while(rnum<50) 
{
    //generate rnum again
}
cnt++;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.