mersenne-twister

C++11 Generating random numbers from frequently changing range

有些话、适合烂在心里 提交于 2019-12-01 17:05:58
Q: How do I generate (many) uniformly distributed integers from a-priory unknown ranges? What is the prefered way in terms of performance (milions of generated numbers)? Context: In my app I have to generate many pseudo random numbers in many places. I use singleton pattern for the generator to maintain reproducibility of the app's run. Distribution is always uniform in my case, but the problem is that there are far too many possible ranges to pre-made the distribution object in C++11 style. What I tried: There are two obvious solutions to this, first is to have one-time distribution objects

C++11 Generating random numbers from frequently changing range

主宰稳场 提交于 2019-12-01 16:52:08
问题 Q: How do I generate (many) uniformly distributed integers from a-priory unknown ranges? What is the prefered way in terms of performance (milions of generated numbers)? Context: In my app I have to generate many pseudo random numbers in many places. I use singleton pattern for the generator to maintain reproducibility of the app's run. Distribution is always uniform in my case, but the problem is that there are far too many possible ranges to pre-made the distribution object in C++11 style.

Best way to seed mt19937_64 for Monte Carlo simulations

我的未来我决定 提交于 2019-11-30 10:56:26
问题 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: mt19937_64 prng; //pseudo random number generator unsigned long seed; //store seed so that

How to properly seed a mersenne twister RNG?

為{幸葍}努か 提交于 2019-11-30 08:34:51
This is actually not as simple as I first thought. In the absence of a hardware RNG, what is the best way to seed a Mersenne Twister? Or should I say, what is an acceptable way to seed a a Mersenne Twister RNG that is used to generate UUID's? There is a nice discussion of pseudo-random number generators here including a section on the proper seeding of PRNGs (see rule 3), which uses md5sum and /dev/random or /dev/urandom to generate seeds. This also includes a number of PRNG alogrithms which are a lot easier to code up (< 10 lines of code) than the MT but are arguably just as good (long

How can I retrieve the current seed of NumPy's random number generator?

北慕城南 提交于 2019-11-30 01:44:41
The following imports NumPy and sets the seed. import numpy as np np.random.seed(42) However, I'm not interested in setting the seed but more in reading it. random.get_state() does not seem to contain the seed. The documentation doesn't show an obvious answer. How do I retrieve the current seed used by numpy.random , assuming I did not set it manually? I want to use the current seed to carry over for the next iteration of a process. The short answer is that you simply can't (at least not in general). The Mersenne Twister RNG used by numpy has 2 19937 -1 possible internal states, whereas a

Best way to seed mt19937_64 for Monte Carlo simulations

丶灬走出姿态 提交于 2019-11-29 22:17:03
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: mt19937_64 prng; //pseudo random number generator unsigned long seed; //store seed so that every run can follow the same sequence unsigned char seed_count; //to help keep seeds from repeating

What algorithm does Math.random use?

对着背影说爱祢 提交于 2019-11-29 14:34:32
Since I've been studying Computer Science, whenever random numbers come up, it's always Mersenne Twister. There's never even a question, no alternative. Just, use Mersenne Twister. So what does JavaScript's Math.random use? It seems like it ought to use Mersenne Twister, since it's apparently without peer, but I can't find any reference to whether it does or not. Does anyone know what it relies on, and/or why it isn't MT, if that's the case? It's likely implementation specific. The ECMAScript specification does not force any algorithm, so a Linux JavaScript implementation might very well use

How reliable is the Random function in Delphi

喜夏-厌秋 提交于 2019-11-29 07:44:36
问题 I am writing a program which write statistical tests in Delphi (must be Delphi) and I've heard that the Random functionality is somewhat odd. You have to call randomize to randomize the seed of the random function when the program starts. I'm wondering if the random function (after calling randomize) is random enough for statistical tests or a Mersenne twister is needed? Does anyone have any insight into random's actual implementation which can tell me how important this is? 回答1: Whether

How is PHP's mt_rand seeded?

99封情书 提交于 2019-11-29 07:08:51
问题 I know PHP's mt_rand() should not be used for security purposes as its results are not cryptographically strong. Yet a lot of PHP code does just that, or uses it as a fallback if better sources of randomness are not available. So how bad is it? What sources of randomness does mt_rand use for seeding? And are there other security problems with mt_rand for cryptographic applications? 回答1: In PHP 5.4, if mt_rand is automatically seeded the first time it's used (PHP source). The seed value is a

Open-source implementation of Mersenne Twister in Python? [closed]

大城市里の小女人 提交于 2019-11-29 02:45:41
Is there any good open-source implementation of Mersenne Twister and other good random number generators in Python available? I would like to use in for teaching math and comp sci majors? I am also looking for the corresponding theoretical support. Edit: Source code of Mersenne Twister is readily available in various languages such as C ( random.py ) or pseudocode (Wikipedia) but I could not find one in Python. Mersenne Twister is an implementation that is used by standard python library. You can see it in random.py file in your python distribution. On my system (Ubuntu 9.10) it is in /usr/lib