Hi Giung,
Here is the source for both functions.
//*****************************************************************************
//! Set the random number generator seed.
//!
//! \param ulSeed is the new seed value to use for the random number generator.
//!
//! This function is very similar to the C library <tt>srand()</tt> function.
//! It will set the seed value used in the <tt>urand()</tt> function.
//!
//! \return None
//*****************************************************************************
void
usrand(unsigned long ulSeed)
{
g_ulRandomSeed = ulSeed;
}
//*****************************************************************************
//! Generate a new (pseudo) random number
//!
//! This function is very similar to the C library <tt>rand()</tt> function.
//! It will generate a pseudo-random number sequence based on the seed value.
//!
//! \return A pseudo-random number will be returned.
//*****************************************************************************
int
urand(void)
{
// Generate a new pseudo-random number with a linear congruence random
// number generator. This new random number becomes the seed for the next
// random number.
g_ulRandomSeed = (g_ulRandomSeed * 1664525) + 1013904223;
// Return the new random number.
return((int)g_ulRandomSeed);
}
Here would be an example of usage.
int main (int argc, char *argv[]){
unsigned long ulNewSeed = 3458;
unsigned int newRand;
usrand(ulNewSeed);
newRand = urand();
return 0;
}
Hope this answers your question.