Unfortunately, that method only works if you need a number between 0
and n. I have a somewhat strange but effective method for generating
random numbers (you specify the upper and lower bounds). It's in an
include file that I've created with several nice functions (let me
know if you want the whole file)
#include <windows.h> //for console functions
#include <stdlib.h> //the standard library
#include <time.h> //for time(NULL)
using namespace std; //the standard namespace
int seed = 1; //helps in randomizing
int Randint(int low, int high)
{
//c++ works so fast that it's tricky to get random numbers, even
if the seed is based on the computer clock
seed += ((time(NULL) + seed) % GetTickCount()); //tries to
randomize even further
srand(GetTickCount() + seed); //seed the
random generator
return (int)((rand() % (high - low + 1)) + low); //returns an
integer based on a randomly generated number
}
>
> number=rand()%6+1; //dice(1-6)