Questions tagged [mt19937]

For questions related to the Mersenne Twister pseudorandom number generator with a period of 2^19337

39 questions
1
vote
4 answers

C++ mt19937 getting the same sequence multiple times

I'm trying to create a deterministic hash generator using a pseudo random number sequence with the mt19937 engine in the library. Therefore, I need to get the same sequence of numbers every time I feed the engine with the same seed. My code…
1
vote
1 answer

Function not updating internal state of mt19937

I have a function that generates and writes random integers: void randint(int min, int max, int times,std::mt19937 rng){ std::uniform_int_distribution dist(min, max); for (int i=0;i
44a3
  • 35
  • 4
1
vote
0 answers

What are the advantages of using a fixed value as the first state in NumPy MT19937?

In NumPy's current implementation, the MT19937 generator takes an entropy input (int or sequence of int), passes it to a hash function implemented by SeedSequence, and uses the returned sequence of numbers as initial state values, except the first…
DanielTuzes
  • 2,494
  • 24
  • 40
1
vote
1 answer

static and random generator in c++

#include #include int gen_ran(void) { static std::random_device rd; static std::mt19937 gen(rd()); static std::uniform_int_distribution dist(0, 9); return dist(gen); } int main() { for (int i = 0; i <…
Ethan
  • 161
  • 2
  • 9
1
vote
1 answer

Visual Studio 2019 c++latest generic URNG function fails to compile after latest update

I have the following generic C++ generic URNG function: template void TestURNG(URNG& urng) { // Uniform distribution used with vector // Distribution is [-5, 5] inclusive uniform_int_distribution dist(-5, 5); …
Kok How Teh
  • 3,298
  • 6
  • 47
  • 85
1
vote
1 answer

How to initialize std::mt19937 when std::random_device entropy is unknown? (VS C++/Windows)

I am attempting to build a simple random number generator, but I wanted to make sure random_device was working properly. I started with the following code: #include #include class Generator { public: Generator() : …
Jatol
  • 51
  • 4
1
vote
1 answer

How is mt19937 prng exactly used for python random module functions?

from random import * seed(5489) hex(getrandbits(32)) # '0xc9a0e034' hex(getrandbits(32)) # '0x38feb21f' I ran this with Python 3.8.2 (not that it should matter too much). This is not what I would expect from a MT19937 32 bit PRNG. To be exact, I…
adbforlife
  • 21
  • 7
1
vote
1 answer

Chosing the random-number-generator at runtime in CPP

I am probably doing more effort than necessary but who cares, let's try to solve this problem: I would like to use the "random_device" generator from in my code. But that might not be available on some systems (according to specs), so I…
István
  • 11
  • 4
1
vote
0 answers

How can I use mt19937 in a class without getting the same random sequence in each instance?

I'm writing code for initializing particle positions in a phase space using a density function. I would like to randomly sample their locations according to an arbitrary distribution, and the easiest way to do this that I found was to make a small…
Liam Clink
  • 189
  • 1
  • 11
0
votes
1 answer

mt19997 C++ object passed by reference always generates the same values

I'm trying to write a code where I create an object mt19937 in a class A that can be used in the class internal functions for generating random numbers and I also want to pass a reference to this same object to various instances of the class B…
0
votes
1 answer

It is proper to make mt19937 static in a class

Let's say I have a class as below: class Test { public: Test() : mt((std::random_device())()), dist1(0, 10), dist2(0, 100) {} void func() { if (dist1(mt) < 4) { // do something } } void func2() { …
Yves
  • 11,597
  • 17
  • 83
  • 180
0
votes
0 answers

std::uniform_real_distribution gives only one number at mingw

I am try to run this code: #include #include void foo() { std::random_device rd; std::mt19937 mt(rd()); std::uniform_real_distribution prob(0, 1); std::cout << prob(mt) << '\n'; } int main() { for (int i = 0;…
dasfex
  • 1,148
  • 2
  • 12
  • 30
0
votes
0 answers

Random Number Generator with mt19937 Not Working Properly

The code is giving me the same number every time I run the program. I can't figure out why. I looked up a tutorial on how to use the seed the generator properly, and for some reason my example won't work. #include #include int…
John K
  • 21
  • 2
0
votes
0 answers

How to determine big O complexity for mt19937 algorithm

Create a length n array to store the state of the generator int[0..n-1] MT int index := n+1 const int lower_mask = (1 << r) - 1 // That is, the binary number of r 1's const int upper_mask = lowest w bits of (not lower_mask) Initialize the generator…
Ari Pili
  • 21
  • 1
0
votes
0 answers

C++ uniform_real_distribution keeps outputting the same values each time

#include #include using namespace std; vector res; int main() { srand(time(NULL)); std::random_device randomDevice; std::mt19937 generator(randomDevice()); std::uniform_real_distribution
Huy Le
  • 1,439
  • 4
  • 19