Questions tagged [mersenne-twister]

The Mersenne Twister is a pseudo-random number generator (PRNG) suitable for Monte-Carlo simulations. It has a long period (2^19937-1) and yet takes very little memory space.

Mersenne Twister(MT) is a pseudorandom number generating algorithm developed by Makoto Matsumoto and Takuji Nishimura in 1996/1997. An improvement on initialization was given in 2002

It has a far longer period and far higher order of equidistribution than any other implemented generators. (It is proved that the period is 2^19937-1, and 623-dimensional equidistribution property is assured.)

Fast generation. (Although it depends on the system, it is reported that MT is sometimes faster than the standard ANSI-C library in a system with pipeline and cache memory.) (Note added in 2004/3: on 1998, usually MT was much faster than rand(), but the algorithm for rand() has been substituted, and now there is not much difference in speed on most platforms.)

Efficient use of the memory. (The implemented C-code mt19937.c consumes only 624 words of working area.)

Source code and documentation for the basic algorithm along with several variations can be found here: http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html

165 questions
10
votes
5 answers

Pseudo-random number generator for cluster environment

How can I generate independent pseudo-random numbers on a cluster, for Monte Carlo simulation for example? I can have many compute nodes (e.g. 100), and I need to generate millions of numbers on each node. I need a warranty that a PRN sequence on…
Charles Brunet
  • 21,797
  • 24
  • 83
  • 124
10
votes
3 answers

Which Mersenne Twister does C++11 provide?

I'm having trouble determining which variant of Mersenne Twister C++11 provides. Looking at Matsumoto and Nishimura ACM paper at Mersenne twister: A 623 Dimensionally Equidistributed Uniform Pseudorandom Number Generator, the authors provide the…
jww
  • 97,681
  • 90
  • 411
  • 885
9
votes
2 answers

Generating pseudo-random 16-bit integers

I need to generate 16-bit pseudo-random integers and I am wondering what the best choice is. The obvious way that comes in my mind is something as follows: std::random_device rd; auto seed_data = std::array
Marius Bancila
  • 16,053
  • 9
  • 49
  • 91
9
votes
3 answers

C++ random yields different numbers for same Mersenne Twister seed when using float precision

I need to run reproducible Monte Carlo runs. That means I use a known seed that I store with my results, and use that seed if I need to run the same problem instance using the same random numbers. This is common practice. While investigating the…
Escualo
  • 40,844
  • 23
  • 87
  • 135
9
votes
4 answers

mersenne twister - is there a way to jump to a particular state?

I am a little unsure about the right forum for this question. It is between theoretical comp. sci./math and programming. I use Mersenne-Twister to generate pseudo random numbers. Now, starting from a given seed, I would like to jump to the n-th…
subhacom
  • 868
  • 10
  • 24
8
votes
0 answers

Mersenne Twister 64: origin of 'd' tempering parameter?

Short version: common MT (and MT64) implementations have an extra tempering parameter 'd'. The papers I've looked at describing MT don't include it. Where is it from? When was it added? Long version! :) I'm looking at using a family of MT's with…
Wuggy
  • 229
  • 2
  • 8
8
votes
2 answers

C++11 Generating random numbers from frequently changing range

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…
teejay
  • 2,353
  • 2
  • 27
  • 36
8
votes
1 answer

What is the effective seed range for Ruby's rand?

Ruby implements PRNGs as "a modified Mersenne Twister with a period of 2**19937-1." 1 The way I understand MT is that it operates on 2^32 different seeds. What confuses me is that Random.new(seed) accepts arbitrarily big numbers such as…
randomguy
  • 12,042
  • 16
  • 71
  • 101
7
votes
3 answers

Testing the quality of PRNGs

I am playing around with PRNGs (like Mersenne Twister and rand() function of stdlib) and I would want a good test that would help me ascertain the quality of random data produced by the PRNGs. I have calculated the value of Pi using random numbers…
Sayan
  • 2,662
  • 10
  • 41
  • 56
7
votes
2 answers

Can I generate cryptographically secure random data from a combination of random_device and mt19937 with reseeding?

I need to generate cryptographically secure random data in c++11 and I'm worried that using random_device for all the data would severely limit the performance (See slide 23 of Stephan T. Lavavej's "rand() Considered Harmful" where he says that when…
Avi Poss
  • 341
  • 4
  • 11
6
votes
1 answer

Why is random.random() not secure in Python?

I came across this question on Stack overflow: How to randomly selection item from a list in Python and they mentioned that it is not suitable for cryptographic/security purposes. So, I found this page in the official documentation: random -…
Hiten
  • 248
  • 2
  • 9
6
votes
3 answers

Java Apache Math3 MersenneTwister VS Python random

I have the task of porting some python code to Scala for research purposes. Now I use the Apache Math3 commons library and am having difficulty with the MersenneTwister. In Python: SEED = 1234567890 PRIMARY_RNG =…
WiR3D
  • 1,465
  • 20
  • 23
5
votes
1 answer

MT19937 does NOT reproduce the same pseudo-random sequence by holding the seed value a constant

I'm writing a checkpoint function in my Monte Carlo simulation in Fortran 90/95, the compiler I'm using is ifort 18.0.2, before going through detail just to clarify the version of pseudo-random generator I'm using: A C-program for MT19937, with…
Gvxfjørt
  • 99
  • 2
  • 7
5
votes
3 answers

R: Extreme bunching of random values from runif with Mersenne-Twister seed

We are facing a weird situation in our code when using R's runif and setting seed with set.seed with the kind = NULL option (which resolves, unless I am mistaken, to kind = "default"; the default being "Mersenne-Twister"). We set the seed using (8…
tchakravarty
  • 10,736
  • 12
  • 72
  • 116
5
votes
1 answer

Distributed sequential random number generation in Ruby 1.9.2

The Random class in Ruby 1.9.2 is guaranteed to generate random numbers in the same order, given a particular seed and range. For instance: r = Random.new(23) r.rand(100) # 83 r.rand(100) # 40 But suppose I want to generate the next…
Trevor Burnham
  • 76,828
  • 33
  • 160
  • 196
1
2
3
10 11