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
0
votes
2 answers

Seeding Mersenne Twister in Web Service

I need to create a web services receiving some data and returning a Random Number. The Random Number has to be generated by Mersenne Twister Algorithm. One of the specification is seeding the Mersenne Twister. Because is a web services do I have to…
Mike
  • 173
  • 2
  • 5
0
votes
0 answers

How to find seed sequence using Mersenne Twister generator

I was trying to find the next seed of the random PN sequence using mersenne twister generator. my code is below- N=10; R=5; A(1:N,1:N) = eye(N); seed=2; rng(seed,'twister'); B = round((rand(25,50))); C=[A;B]; I am initializing first seed=2…
Blair rick
  • 13
  • 2
0
votes
1 answer

A new random vector with each call

I want generate a random vector including n elements in the range of [min,max], which works fine with the mersenne twister and my code below. Obviously, every time I call my rand_vec function, I get the same output. But I need the random function to…
user1309940
0
votes
1 answer

Random unsigned integer generated via 32 threads (C++11)

As a programming exercise I thought it would be fun to try to write a program which uses multiple threads the generate a random number. This method would introduce the "chaos" of the OS scheduler to add randomness. The idea of 32 threads is that…
Victor Stone
  • 498
  • 5
  • 18
0
votes
2 answers

C++ What is contained in the lower 32 bits: Seeding mt

I have a line of code that uses a nano second grab of the high precision clock to seed mersenne twister psudo-random number generator. Something along the lines of…
joshu
  • 463
  • 8
  • 18
0
votes
2 answers

Random real in [0..1[ using Mersenne Twister

I'm trying to make a model of a zombie apocalipse in c++ using simple structs and a when I'm randomizing the population, I need some fields of the struct to have a value in the interval [0..1[. As I'm interested in a more statistically correct…
Pedro
  • 333
  • 1
  • 5
  • 24
0
votes
1 answer

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: //! Represents the state of a particular generator typedef struct{ uint x; uint…
user1855952
  • 1,515
  • 5
  • 26
  • 55
0
votes
1 answer

Why there isn't any sub-stream capability of mersenne twister random number generator in MATLAB and how we can solve it?

I'm using parallel computing and i need different sub-streams (independent sub-stream) of random numbers in every worker (logical core) in MATLAB. When i set sub-streams to mlfg6331_64 or mrg32k3a My performance with neural network in parfor loop is…
Eghbal
  • 3,892
  • 13
  • 51
  • 112
0
votes
1 answer

Dangled with std::mt19937 and profiling the code with gprof

I have in my .h file this code: std::mt19937 rng(time(NULL)); // mersenne numbers int random(int n) { std::uniform_int_distribution distribution(0, n); return distribution(rng); } but I never call random(). When I am profiling the code…
gsamaras
  • 71,951
  • 46
  • 188
  • 305
0
votes
1 answer

How many states in a PRNG (say Mersenne Twister) and what is the distribution over next state?

For a PRNG like the Mersenne Twister which has a period of 2^19937-1, are there precisely that many states for the PRNG? i.e. the states start repeating at that point because there are no more states for the PRNG to be in? As a follow up, what is…
0
votes
2 answers

How to use MT (or similar) RNG algorithm in CPP implementation?

I want to implement MT alg in CPP (I just can't use C++11 sadly) I've found a lot of algorithms like SFMT, dSFMT, some versions of Tiny MT etc; but as I saw the documentation of those algs, I think they works for range like <0,2) (from doxygen…
Bartłomiej Sobieszek
  • 2,692
  • 2
  • 25
  • 40
0
votes
2 answers

Will this function return uniformly distributed random values?

I'd like to return uniform random values in a range. The magnitude of the range and the minimum value are precomputed. I'm using the reference implementation of the double precision Mersenne Twister distributed by the team at Hiroshima University.…
OregonTrail
  • 8,594
  • 7
  • 43
  • 58
0
votes
1 answer

Error while running mtgp32 cuRAND device API example

I am trying to use device version of Mersenne Twister from cuRAND. I tried to use second example in the cuRAND API docs: 3.6. Device API Examples I took the liberty of copying the code into separate gist: curand.cu This is what I get while…
dejnon
  • 3
  • 2
0
votes
2 answers

Why is this class not Serializable?

I was using the Mersenne-Twister implementation at http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/VERSIONS/JAVA/MTRandom.java as a drop-in replacement for the default java.util.Random class. However, four fields (an int, a boolean and two byte[])…
Chinmay Kanchi
  • 62,729
  • 22
  • 87
  • 114
0
votes
2 answers

Largest Seed Possible for Mersenne Twister c++

I would like to find out the largest value I can seed a random number generator in c++. My code is as follows: mt19937 myRandomGenerator(seed); How large can the variable, seed be? I have noticed that if the value becomes too large, the random…
covertbob
  • 691
  • 2
  • 8
  • 15
1 2 3
10
11