mersenne-twister

Why do the numpy and random modules give different random numbers for the same seed?

房东的猫 提交于 2019-12-10 16:17:03
问题 For the same seed, why does random.random() produce different random values when compared to numpy.random(). My understanding is that they both use the Mersenne Twister to generate random values. import random as rnd import numpy as np rnd.seed(1) np.random.seed(1) rnd.random() np.random.rnd() 0.13436... 0.41702... 回答1: The random module and numpy.random both use a mt19937 to generate random numbers. Because of this, we can copy the state of one from one generator to the other to see if they

CUDA's Mersenne Twister for an arbitrary number of threads

两盒软妹~` 提交于 2019-12-07 22:58:41
问题 CUDA's implementation of the Mersenne Twister ( MT ) random number generator is limited to a maximal number of threads/blocks of 256 and 200 blocks/grid, i.e. the maximal number of threads is 51200 . Therefore, it is not possible to launch the kernel that uses the MT with kernel<<<blocksPerGrid, threadsPerBlock>>>(devMTGPStates, ...) where int blocksPerGrid = (n+threadsPerBlock-1)/threadsPerBlock; and n is the total number of threads. What is the best way to use the MT for threads > 51200 ?

CUDA's Mersenne Twister for an arbitrary number of threads

蓝咒 提交于 2019-12-06 16:00:15
CUDA's implementation of the Mersenne Twister ( MT ) random number generator is limited to a maximal number of threads/blocks of 256 and 200 blocks/grid, i.e. the maximal number of threads is 51200 . Therefore, it is not possible to launch the kernel that uses the MT with kernel<<<blocksPerGrid, threadsPerBlock>>>(devMTGPStates, ...) where int blocksPerGrid = (n+threadsPerBlock-1)/threadsPerBlock; and n is the total number of threads. What is the best way to use the MT for threads > 51200 ? My approach if to use constant values for blocksPerGrid and threadsPerBlock , e.g. <<<128,128>>> and use

How to use Mersenne Twister random number generation library in C?

泪湿孤枕 提交于 2019-12-06 11:17:20
I want to use one of the Mersenne Twister C libraries (e.g. tinymt , mtwist , or libbrahe) so I can use it as a seed for rand() in a C program. I wasn't able to find a simple minimalistic example on how to do this. I got this far with the mtwist package, but through pjs's comments I've realized that this is the wrong way to do it: #include <stdio.h> #include <stdlib.h> #include "mtwist.h" int main() { uint32_t random_value; random_value = mt_lrand(); srand(random_value); printf("mtwist random: %d; rand: %d\n", random_value, rand()); return 0; } (Originally I wrote that this code wouldn't

How do I use boost::random_device to generate a cryptographically secure 64 bit integer?

大城市里の小女人 提交于 2019-12-05 00:45:18
问题 I would like to do something like this: boost::random_device rd; boost::random::mt19937_64 gen(rd()); boost::random::uniform_int_distribution<unsigned long long> dis; uint64_t value = dis(gen); But I've read that a mersenne twister is not cryptographically secure. However, I've also read that a random_device could be, if its pulling data from /dev/urandom which is likely on a linux platform (my main platform). So if the random_device is non-deterministically random and its used to seed the

Testing the quality of PRNGs

戏子无情 提交于 2019-12-04 23:11:59
问题 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 generated by the PRNGs, and I find rand() and Mersenne Twister to be very close to offer a distinction (do I need to scrutinize after 10 decimal points?). I do not have much idea about Monte Carlo simulations; please let me know about some algorithm

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

眉间皱痕 提交于 2019-12-03 18:38:05
问题 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. 回答1: The short answer is that you simply can't (at least not

Pseudo-random number generator for cluster environment

时光总嘲笑我的痴心妄想 提交于 2019-12-03 04:34:46
问题 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 one node will not overlap the PRN sequence on another node. I could generate all PRN on root node, then send them to other nodes. But it would be far too slow. I could jump to a know distance in the sequence, on each node. But is there such an

Clang performance drop for specific C++ random number generation

久未见 提交于 2019-12-02 23:55:01
Using C++11's random module, I encountered an odd performance drop when using std::mt19937 (32 and 64bit versions) in combination with a uniform_real_distribution (float or double, doesn't matter). Compared to a g++ compile, it's more than an order of magnitude slower! The culprit isn't just the mt generator, as it's fast with a uniform_int_distribution . And it isn't a general flaw in the uniform_real_distribution since that's fast with other generators like default_random_engine . Just that specific combination is oddly slow. I'm not very familiar with the intrinsics, but the Mersenne

Pseudo-random number generator for cluster environment

泄露秘密 提交于 2019-12-02 17:45:33
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 one node will not overlap the PRN sequence on another node. I could generate all PRN on root node, then send them to other nodes. But it would be far too slow. I could jump to a know distance in the sequence, on each node. But is there such an algorithm for Mersenne-Twister or for any other good PRNG, which can be done with a reasonable amount of time