I'm a college student majoring in the Computer Science field, and this was an assigned project for a class. It's nothing more than a test to show the efficiency of different sorting algorithms and the efficiency difference between sequential and binary searches for 10,000,000 numbers. All of that I understand, and executed perfectly using the STL.
The project requested that the range of the random numbers generated be 0 - 99,999. Of course, rand() returns unsigned int, if I recall correctly, which would max out to 32,727 (under the maximum of the range) as it showed in my testing. I ended up using the Mersenne Twister Random Number Generator in my program, but as a junior in college this seemed a bit extreme. I tried using typecasts on my srand and rand functions but could not overwrite the return type for rand(). This is what I tried:
srand((unsigned long int)(time(NULL)));
and, in using a vector to store my numbers and a For loop...
for(unsigned int i = 0; i < sortMe.size(); i++)
[INDENT]sortMe[i] = ((unsigned long int)rand()) % 100000;[/INDENT]
I know that unsigned long int (and, really, long int) would hold a value that exceeds 99,999 but regardless of how and where I typecasted srand() and rand() the value would never exceed 32,767. Is it possible to override the int rand() function in the cstdlib (stdlib.h)? I even attempted:
#undef RAND_MAX
#define RAND_MAX 100000
to override the value of RAND_MAX but still, the return type of int on rand() is preventing this. Any help would be appreciated as I cannot see how my professor would want a junior level college student to random that range of numbers w/o any knowledge of "randomizing" outside of the rand() function.
If you'd like to see my complete project, I'll gladly post it.