我试图找到最有效的方法来为我正在研究的 MC 模拟生成随机数。我已经阅读了很多关于双精度 Mersenne Twister 算法的内容,我想在继续之前了解一些基本的东西。
我编译并运行了官方 dSFMT 文件提供的测试,这对我的系统来说是最好的结果:
C:\TDM-GCC-64\C++ Tests\dSFMT>test-sse2-M19937 -s
consumed time for generating 100000000 randoms.
ST BLOCK [0, 1) AVE: 115ms.
ST BLOCK (0, 1] AVE: 108ms.
ST BLOCK (0, 1) AVE: 106ms.
ST BLOCK [1, 2) AVE: 77ms.
ST SEQ [0, 1) 1 AVE: 174ms.
ST SEQ [0, 1) 2 AVE: 207ms.
total = 500014655.815776
ST SEQ (0, 1] 1 AVE: 173ms.
ST SEQ (0, 1] 2 AVE: 205ms.
total = 500035344.184224
ST SEQ (0, 1) 1 AVE: 209ms.
ST SEQ (0, 1) 2 AVE: 247ms.
total = 500014655.815776
ST SEQ [1, 2) 1 AVE: 173ms.
ST SEQ [1, 2) 2 AVE: 204ms.
total = 1500064655.815183
我的问题是:
- 为什么生成 [1,2) 比 [0,1) 快?
- 为什么块生成比顺序生成快?分配一个大数组并且必须删除和重写它不应该更慢吗?
- 如果我需要生成 1e12 数字,最好的策略是什么?如果分块进行,最佳数组大小是多少?