: : EDIT: I checked the VS2005 implementation, and it's indeed a bit
: : different. It's sort of linear (but not entirely) ... so, yes, it is
: : possible to get period >= RAND_MAX
: :
: : Best Regards,
: : Richard
: :
: : The way I see it... Well, it's all pretty blurry
:
: I'm interested to see the implementation too. But couldn't find the
: definition of rand() function. Can you please tell where can I find
: the implementation of rand()?
: --
: ~Donotalo()
I take it you downloaded the Win32 platform SDK? If you search through the rand.c file you can find the implementation.
To make it easier for you:
/***
*rand.c - random number generator
*
* Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
*
*Purpose:
* defines rand(), srand() - random number generator
*
******************************************************************/
...
int __cdecl rand (
void
)
{
#ifdef _MT
_ptiddata ptd = _getptd();
return( ((ptd->_holdrand = ptd->_holdrand * 214013L
+ 2531011L) >> 16) & 0x7fff );
#else /* _MT */
return(((holdrand = holdrand * 214013L + 2531011L) >> 16) & 0x7fff);
#endif /* _MT */
}
There's the basic multiplication, but also an addition, and after that the lower 16 bits are discarded, and the higher 16 are used.
Best Regards,
Richard
The way I see it... Well, it's all pretty blurry