问题标签 [mersenne-twister]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
c++ - Best way to seed mt19937_64 for Monte Carlo simulations
I'm working on a program that runs Monte Carlo simulation; specifically, I'm using a Metropolis algorithm. The program needs to generate possibly billions of "random" numbers. I know that the Mersenne twister is very popular for Monte Carlo simulation, but I would like to make sure that I am seeding the generator in the best way possible.
Currently I'm computing a 32-bit seed using the following method:
I have a feeling there are much better ways to assure non-repeating new seeds, and I'm quite sure mt19937_64 can be seeded with more then 32-bits. Does anyone have any suggestions?
java - Java Apache Math3 MersenneTwister VS Python 随机
我的任务是将一些 python 代码移植到 Scala 以进行研究。现在我使用 Apache Math3 公共库,但在使用 MersenneTwister 时遇到了困难。
在 Python 中:
在斯卡拉:
我在这里想念什么?两者都是 MersenneTwister 的,
并且Int.MaxValue = 2147483647 = (2**31) - 1
c++ - C++11 从频繁变化的范围生成随机数
问:如何从先验未知范围生成(许多)均匀分布的整数?就性能(数百万生成的数字)而言,首选方式是什么?
上下文:在我的应用程序中,我必须在许多地方生成许多伪随机数。我对生成器使用单例模式来保持应用程序运行的可重复性。在我的情况下,分布总是统一的,但问题是有太多可能的范围来预先制作 C++11 风格的分布对象。
我尝试了什么:有两个明显的解决方案,第一个是一次性分布对象,第二个是使用模将随机数从最广泛的范围转换为所需的范围。但不知何故,我怀疑这些是最好的:)
重复的问题
android - MersenneTwister - Android(java)和C(Arduino)中的相同伪随机数
我必须使用一个伪随机数生成器在不同平台上使用相同的种子获得相同的数字。
我试图在 Android(java) 和 Arduino(c) 的随机类中设置“种子”,它们给我不同的数字和相同的种子,我需要的是两个系统中相同的数字和相同的种子。
因此,我尝试使用“Mersenne Twister”在两个系统中获得相同的伪随机数。
这是我在 Arduino 库中的代码:
这是我在 java 中的 Mersenne Twister: http ://www.cs.gmu.edu/~sean/research/mersenne/MersenneTwister.java或http://www.cs.gmu.edu/~sean/research/mersenne /MersenneTwisterFast.java 两个.java 中的代码或多或少是相等的,至少结果是一样的。
你能帮我为什么我不能得到相同的伪随机数吗?
在此先感谢,最好的问候。
algorithm - 梅森捻线器的时间复杂度是多少?
我读过“梅森捻线器的计算复杂度是 O(p 2 ),其中 p 是多项式的次数”。
- 这是什么意思?
- 这是指哪个多项式?
- 此外,计算复杂度是时间复杂度的另一种说法,还是与算法运行所需的空间量有关?
c++11 - 与 std::mt19937 挂钩并使用 gprof 分析代码
我的 .h 文件中有这段代码:
但我从不打电话random()
。
当我使用 gprof 分析代码时,我得到:
怎么了?
matlab - 为什么 MATLAB 中没有 mersenne twister 随机数生成器的任何子流功能,我们如何解决?
我正在使用并行计算,我需要在MATLAB
. 当我设置sub-streams
为mlfg6331_64
或mrg32k3a
我在循环中使用神经网络的性能parfor
非常低,但是当我生成随机权重时parfor
,rnf - mersenne twister
我的性能更高。
为什么
MATLAB
不支持mersenne twister
作为子流?我的MATLAB
版本是R2014a
. 是否支持此功能R2014b
?如何使用
mersenne twister
before创建独立的随机数流parfor
并将(例如神经网络的权重)插入parfor
循环?(例如在之前使用循环parfor loop
)
php - mt_rand() 是否两次生成相同的数字?
我正在尝试生成唯一的令牌 ID,我可以使用mt_rand()
吗?
会mt_rand()
产生两次相同的数字吗?
random - Best way to maintain an RNG state in multiple devices in openCL
So I'm trying to make use of this custom RNG library for openCL: http://cas.ee.ic.ac.uk/people/dt10/research/rngs-gpu-mwc64x.html
The library defines a state struct:
And in order to generate a random uint, you pass in the state into the following function:
which updates the state, so that when you pass it into the function again, the next "random" number in the sequence will be generated.
For the project I am creating I need to be able to generate random numbers not just in different work groups/items but also across multiple devices simultaneously and I'm having trouble figuring out the best way to design this. Like should I create 1 mwc64x_state_t object per device/commandqueue and pass that state in as a global variable? Or is it possible to create 1 state object for all devices at once? Or do I not even pass it in as a global variable and declare a new state locally within each kernel function?
The library also comes with this function:
Which supposedly is supposed to split up the RNG into multiple "streams" but including this in my kernel makes it incredibly slow. For instance, if I do something very simple like the following:
Then the kernel call becomes around 40x slower.
The library does come with some source code that serves as example usages but the example code is kind of limited and doesn't seem to be that helpful.
So if anyone is familiar with RNGs in openCL or if you've used this particular library before I'd very much appreciate your advice.
c++ - 梅森麻花籽作为
我想将随机数生成器状态保持为成员变量,因此从此类生成的每个对象都有其一个。有必要的是,每次生成对象时,种子也会发生变化。
我做了以下事情,即通过对象的构造函数更改种子。我用 time(NULL) 做的播种但这不够准确,因为对象的创建速度比一秒钟之内快,哈哈。
我正在努力使用 [ Seeding rand() for a C++ class by bames53 中描述的方法。
包括这件作品
进入类声明会产生以下错误:
错误:没有构造函数实例“std::merseen_twister_engine<_Ty,_Wx, many more things> 参数类型是 (std::chrono::system_clock::rep)
现在我不完全知道错误来自哪里以及如何解决我的问题。请记住,我或多或少是一个 c++ 新手。谢谢!