What algorithm is Rand() based on in C language? [duplicate]

℡╲_俬逩灬. 提交于 2020-02-08 09:14:05

问题


I have been researching the source code of Rand() for a while, but until now I couldn't figure out the whole picture of the function.

The following are the source codes found and researched by me:

rand.c

random.c

Could somebody provide some advices or assistance for me?

Thanks a million!


回答1:


It's not required to be based on any specific algorithm but many will use a linear congruential algorithm to generate the sequences. This basically changes the seed along the following lines:

seed = (seed * multiplier + adder) % modulo

and then deliver some portion of the seed as a random value. The values for multiplier, adder and modulo can vary quite a bit.




回答2:


Rand is based on several things like mac address which should be unique on every machine. there are several implementations to verify that the returned value is "random"



来源:https://stackoverflow.com/questions/30161790/what-algorithm-is-rand-based-on-in-c-language

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!