Hi,
could you please give me a hint about the algorithm that c++ uses when we use rand () command.
there are many algorithm. but most simple one is:Linear Congruential Generator(LCG)
does c++ use (LCG) when we use rand () ??
thanks for your help
Printable View
Hi,
could you please give me a hint about the algorithm that c++ uses when we use rand () command.
there are many algorithm. but most simple one is:Linear Congruential Generator(LCG)
does c++ use (LCG) when we use rand () ??
thanks for your help
I don't think the standard defines rand()'s algorithm.
But have a look here(C++11):
Pseudo-random number generation - Cppreference
Why not find it out yourself?
Write a program that uses rand() and step into it with a debugger.
My compiler uses:
Yours might differ.Code:return( ((ptd->_holdrand = ptd->_holdrand * 214013L + 2531011L) >> 16) & 0x7fff );
The standard does not mandate what algorithm is used to implement functions, but rather its requirements, what input it must take and what it must return. It is up to the compiler vendor to implement that.
thanks for your help
That is what I meant by requirements. You just stated it a little more detailed.
I think srand is what you looking for... check cplusplus reference