小编Sun*_*nny的帖子

/ dev/random权限被拒绝

我正在阅读随机数和他们的一代.自从我开始编程以来,我对随机性很感兴趣.我读到Linux内核也使用随机数生成架构.

The structure consists of a two-level cascaded sequence of pools coupled with 
CSPRNGs.
Each pool is a large group of bits which represents the current state of the 
random number generator. The CSPRNGs are currently based on SHA-1, but the 
kernel developers are considering a switch to SHA-3.

The kernel RNG produces two user-space output streams. One of these goes to 
/dev/urandom and also to the kernel itself; the latter is useful because there 
are uses for random numbers …
Run Code Online (Sandbox Code Playgroud)

linux random linux-kernel

4
推荐指数
1
解决办法
7602
查看次数

为什么小数点后的数字全为零?

我想执行一些计算,我希望结果正确到一些小数位,比如12.所以我写了一个样本:

#define PI 3.1415926535897932384626433832795028841971693993751
double d, k, h;
k = 999999/(2*PI);
h = 999999;
d = PI*k*k*h;
printf("%.12f\n", d);
Run Code Online (Sandbox Code Playgroud)

但它给出了输出:

79577232813771760.000000000000
Run Code Online (Sandbox Code Playgroud)

我甚至使用了setprecision(),但相同的答案却是指数形式.

cout<<setprecision(12)<<d<<endl;
Run Code Online (Sandbox Code Playgroud)

版画

7.95772328138e+16
Run Code Online (Sandbox Code Playgroud)

使用长双,但徒劳无功.

除了在long long int类型中分别存储整数部分和小数部分之外,还有什么办法吗?

如果是这样,可以做些什么来准确得到答案?

c c++ floating-point-precision

4
推荐指数
1
解决办法
822
查看次数

矢量与索引和迭代器

我只是想问一下这里发生了什么,我哪里出错了?

vector<int> a(5);

for(int i=0; i<5; i++)    cin>>a[i];            //Input is 1 2 3 4 5

for(int i=0; i<5; i++)    cout<<a[i]<<" ";      //Prints correct, 1 2 3 4 5
cout<<endl;

for(VI::iterator it = a.begin(); it!=a.end(); ++it) {
    cout<<a[*it]<<" ";                          //Prints incorrect output
}
cout<<endl;
Run Code Online (Sandbox Code Playgroud)

看起来,错误输出中的最后一个元素是a[*(a.end()-1)]第一个元素,它实际上应该是缺少的.

c++ iterator vector

3
推荐指数
1
解决办法
140
查看次数