Random Number





-6
Date Submitted Thu. Oct. 13th, 2005 7:12 PM
Revision 1 of 1
Coder mattrmiller
Tags CPP | Number | Random
Comments 0 comments
Random Numbe
int RandomNumber(int nMin, int nMax, BOOL bSeed = true)
{
        // Declare variables
        static time_t stTime = 0;
        int nRandom;

        // Seed the rand() function
        if (stTime == 0 || bSeed == true)
        {
                stTime = GetTickCount();
                srand((unsigned) stTime);
        }

        // Generate random number
        nRandom = nMin + (int)((double)rand() / RAND_MAX * (nMax - nMin));

        return nRandom;
}

Hacked n00b

Comments

There are currently no comments for this snippet.

Voting