How can I get the sourcecode for rand() (C++)?

后端 未结 6 1525
春和景丽
春和景丽 2020-12-31 11:01

I\'m new to programming.

I want to know exactly what rand() does.

Searching only yields examples on its usage. But none explain each step of how the function

6条回答
  •  余生分开走
    2020-12-31 11:40

    The simplest reasonably good pseudo-random number generators are Linear Congruential Generators (LCGs). These are iterations of a formula such as

    X_{n+1} = (a * X_n  +  c) modulo m
    

    The constants a, c, and m are chosen to given unpredictable sequences. X_0 is the random seed value. Many other algorithms exists, but this is probably enough to get you going.

    Really good pseudo-random number generators are more complex, such as the Mersenne Twister.

提交回复
热议问题