I think you'd be better off just call srand() occasionally (or just
once when your code starts).
I tend to just call "srand(time(NULL))" near my program entry point
and leave it at that, it seems pretty random to me! ;-)
The last line (the return) is all you need really for a ranged
random number.
Also, even though PCs are getting faster & faster, calling time()
once and GetTickCount() twice for *every* random number seems a bit
excessive, especially as GetTickCount() will probably be returning
the same number since the calls are only a few instructions apart!
-----------
Allan
--- In beginnersroguelikedevelopment@yahoogroups.com, "gamer_2k4"
<gamer_2k4@y...> wrote:
> 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)