兰德功能 [英] rand function

查看:93
本文介绍了兰德功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

rand函数使用什么算法?

what algorithm does the rand function use?

推荐答案

bo *@coolgroups.com 写道:
rand函数使用什么算法?
what algorithm does the rand function use?



阅读man,info或者其他任何页面找出来!


-

Ian Collins。


Read the man, info or whatever page and find out!

--
Ian Collins.




< bo*@coolgroups.com>在消息中写道

news:11 ********************** @ v46g2000cwv.googlegr oups.com ...

<bo*@coolgroups.com> wrote in message
news:11**********************@v46g2000cwv.googlegr oups.com...
rand函数使用什么算法?
what algorithm does the rand function use?




标准中没有指定算法(本例中为C标准)。

请注意,它只需要提供16位。查看编译器的RAND_MAX

的值。



The algorithm isn''t specified in the standard (the C standard in this case).
Note that it is only required to deliver 16 bits. See the value of RAND_MAX
for your compiler.


< bo*@coolgroups.com>写道:
<bo*@coolgroups.com> wrote:
rand函数使用什么算法?
what algorithm does the rand function use?




如其他地方所述,无论设计者选择使用什么。


以下链接表明:


static unsigned long int next = 1;


int rand (void)// RAND_MAX假设为32767

{

next = next * 1103515245 + 12345;

return(unsigned int)(next / 65536)%32768;

}


至少可以接受。如果想要一个快速而肮脏的发生器,并且在不同的平台上具有统一的结果,那么可以使用它。调用

rand()可能会给不同的编译器带来不同的结果。我还记得在网上的其他地方看到12345的片段。

http://cer.freeshell.org/renma/


这篇关于兰德功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆