gcc执行rand() [英] gcc implementation of rand()

查看:154
本文介绍了gcc执行rand()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试了好几个小时才发现gcc中使用的rand()函数的实现......
如果有人能够引用包含它的实现的文件或实现的网站,我将非常感激。

I've tried for hours to find the implementation of rand() function used in gcc... It would be much appreciated if someone could reference me to the file containing it's implementation or website with the implementation.

顺便说一下,哪个目录(如果有问题,我使用Ubuntu)包含gcc编译器的c标准库实现?

By the way, which directory (I'm using Ubuntu if that matters) contains the c standard library implementations for the gcc compiler?

推荐答案

rand 包含对函数 __ random __ random_r in random_r.c。

rand consists of a call to a function __random, which mostly just calls another function called __random_r in random_r.c.

请注意,上面的函数名称是hyp erlinks到版本2.15的glibc源代码库。

Note that the function names above are hyperlinks to the glibc source repository, at version 2.15.

glibc随机库支持两种生成器:一个简单的 linear congruential 之一,以及更复杂的线性反馈移位寄存器一个。在调用 rand 时使用的默认全局生成器的实例可以使用线性反馈移位寄存器生成器(请参见 unsafe_state.rand_type )。

The glibc random library supports two kinds of generator: a simple linear congruential one, and a more sophisticated linear feedback shift register one. It is possible to construct instances of either, but the default global generator, used when you call rand, uses the linear feedback shift register generator (see the definition of unsafe_state.rand_type).

这篇关于gcc执行rand()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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