You have two problems with your code.
The first, is you are always replacing the seed with the current time. The second is your not performing a test to see if you can 'evenly' take the modulus.
If your going to use the default random number generator here is perhaps a good way to use it:
CODE
int rrand(int min, int max)
{
//what is the magnitude of the random number
int mag = max - min;
//figure out at what point our random numbers are
//useless, any numbers above the cap will result
//in an uneven distribution (more 3's than 8's for
//example).
int cap = (RAND_MAX /mag)*mag;
//make the new seed, the next random number
//xored with the current time
int seed = time(0) ^ rand();
//keep picking random numbers until we are good
int r;
do
{
r = rand();
} while (r < cap);
//return the random number
return r%mag+min;
}
The nice thing about the above method is it will work with any random number generator (just replace rand and RAND_MAX with appropriate values), which produces integers (they all fundamentally return integers). Just keep in mind the random number generator your using is predicatable. The only way to fix the predictability is to switch random number generators, but that makes it alot harder (I personally never use the C random number generator, but I am also getting a masters in cryptography).
You should read:
http://www.dreamincode.net/forums/showtopic24225.htm even though I don't like the rand function, the tutorial is excellent at describing the algorithm.
This post has been edited by salindor: 9 Jun, 2007 - 06:04 AM