c++ - WELL PRNG 不工作?(也许)

标签 c++ random static-libraries prng

我正在尝试使用 WELL PRNG 的特定实现,据说比原来的更好。 link to the code

但是我遇到了一些麻烦。无论我如何播种,它都只会输出相同的数字。我想我可能只是用错了,但一直没能弄清楚我的错误。不幸的是,PRNG 的来源对我来说是完全不透明的。

我的代码:

#include <iostream>
#include <WELL44497a_new.h>

void pause()
{
    std::string dummy;
    std::cout << "Press enter to continue...";
    std::getline(std::cin, dummy);
}

int main(int argc, char** argv) {
    using std::cout;
    using std::cin;
    using std::endl;
    cout<<"Hello"<<endl;
    pause();
    unsigned int rngseed;
    cout<<"Input RNG seed:";
    cin>>rngseed;
    cout<<"The RNG seed is:";
    cout<<rngseed<<endl;
    pause();
    InitWELLRNG44497(&rngseed);
    int i=1;
    for (i;i<100;i++){
        unsigned long rngtest=WELLRNG44497();
        cout<<rngtest<<endl;
    }
    pause();
    return 0;
}

最佳答案

根据评论 squeamish-ossifrage 我修改了代码。以下代码似乎有效:

...
cin>>rngseed;
cout<<"The RNG seed is:";
cout<<rngseed<<endl;
pause();
unsigned int rngseed_arr[1391];
int i=0;
for (i;i<1391;i++){
    rngseed_arr[i]=rngseed+i;
}
InitWELLRNG44497(rngseed_arr);
i=1;
...

关于c++ - WELL PRNG 不工作?(也许),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26538416/

相关文章:

c++ - GLTessellator 崩溃

random - 如何在 Tableau 中生成伪随机数和行计数

linux - 我怎样才能用尽/开发/随机测试?

python - 在 Python 中使用 numpy.random.choice 更快的替代方案?

c++ - 如何在解析过程中区分 IP 地址和域名

c++ - 是否允许在 constexpr 函数中进行函数指针比较?

ffmpeg - Android 上的静态链接 FFmpeg 库

python - 尝试使用 C 库并使用 swig 将其公开给 Windows 中的 Python。关于静态与动态以及使用 Visual Studio for swig 的问题

c++ - visual studio 配置类型 dll : how to turn off lib overwrite?

c++ - "munch"是什么?它是如何与 cfront 一起使用的