i have this code and i am trying to make this

cout << (rand () % (1 + max - min) + min ) << "\t";

into something like this

cout << rand (range) << "\t";

and this the code

#include <iostream>
using namespace std;

int main ()
{
    srand ((unsigned int) time(0));
    int min, max;
    cout << "Enter a min. number." << endl;
    cin >> min;
    cout << "Enter a max. number." << endl;
    cin >> max;
    
    for ( int j= 0; j < 10; j++ )
    {
        for ( int i = 0; i < 10; i++)
        {
            cout << (rand () % (1 + max - min) + min ) << "\t";
        }
    cout << endl;
    }
}

help me i dont know what to change or do. any tips would be great. thks

Do you mean your trying to create a new function that generates pseudo-random integers? I hope your not trying to pass something to rand().

int rand(void);

i am trying to take all of this
% (1 + max - min) + min
and store it in range
so im guessing it should be something like
range = (1 + max - min) + min
but thats not it and i dont know how to % it to have my limits

What I would do is create my own rand function say my_rand()

int my_rand(unsigned int max, unsigned int min)
{
int ans;
/*do something here to generate answer*/
/*hint: ans = (rand () % (1 + max - min) + min )*/
return ans;
}
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.