What is the greatest possible range of rand()? I want to make it that of a long signed integer, but my program crashes. Is there another way to get that range?

Recommended Answers

All 4 Replies

The max of rand() is system-dependent.

Show us what you are doing, there may be a different reason for your program crash.

I just need to generate 'n' random numbers from within as large a range as the system will allow. Here is my code:

void randomNumGen(node *root, int n){
    int randNumResult=0;
    int j;
    for (int i=0; i<n; i++){
        randNumResult=rand ();
        if(!(search(randNumResult, root, j))
             insert(randNumResult, root);
    }
}

There is a macro 'RAND_MAX' which gives you the maximum, but it is not defined in _all_ systems.

You may product two random numbers generated by the rand() function to get a bigger random number. That's just an example. You can create your own random number generator function.

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.