prng

mt19937 and uniform_real_distribution

☆樱花仙子☆ 提交于 2019-12-12 11:04:27
问题 I am trying to find an efficient way to implement a uniform(0,1) distribution. Since I have to generate a very large number of samples, I chose mt19937 as engine. I am using the version from the boost library. My question is: what is the difference between using the output of the engine itself vs using uniform_real_distribution? Option #1 std::random_device rd; boost::mt19937 gen(rd()); boost::random::uniform_real_distribution<double> urand(0, 1); for ( int i = 0; i < 1E8; i++ ) { u = urand

How (if at all) does a predictable random number generator get more secure after SHA-1ing its output?

徘徊边缘 提交于 2019-12-12 08:29:22
问题 This article states that Despite the fact that the Mersenne Twister is an extremely good pseudo-random number generator, it is not cryptographically secure by itself for a very simple reason. It is possible to determine all future states of the generator from the state the generator has at any given time, and either 624 32-bit outputs, or 19,937 one-bit outputs are sufficient to provide that state. Using a cryptographically-secure hash function, such as SHA-1, on the output of the Mersenne

What platforms offer SystemRandom?

故事扮演 提交于 2019-12-10 16:17:46
问题 Python's random.SystemRandom provides cryptographic-quality pseudorandom numbers. What platforms is it supported on? Most importantly, are there any platforms that it is not supported on, and if so, which ones? Can anyone provide any information about how portable it is? 回答1: From http://docs.python.org/library/random.html The random module also provides the SystemRandom class which uses the system function os.urandom() to generate random numbers from sources provided by the operating system.

Is PHP's rand function really so bad? [closed]

允我心安 提交于 2019-12-10 01:38:29
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . I know that it is encouraged to use mt_rand() over rand() because it uses the Mersenne Twister over whatever PRNG rand() uses, but

Getting a random real number in a certain range using WELL512

江枫思渺然 提交于 2019-12-09 18:38:30
问题 I'm using the WELL512 pseudorandom number generator function described in this paper. The function returns a random unsigned long value. How do I use this return value to produce a random real number within a certain range - like a float between 340.92491 and 859812.53198 inclusive. The documentation for the C rand() function seems to warn against using mod. 回答1: Well, mathematically it's just: min_value + (max_value - min_value) * (my_random() / (long double)ULONG_MAX) (Assuming my_random()

Finding seeds for a 5 byte PRNG

我的未来我决定 提交于 2019-12-09 17:46:31
问题 An old idea, but ever since then I couldn't get around finding some reasonably good way to solve the problem it raised. So I "invented" (see below) a very compact, and in my opinion, reasonably well performing PRNG, but I can't get to figure out algorithms to build suitable seed values for it at large bit depths. My current solution is simply brute-forcing, it's running time is O(n^3). The generator My idea came from XOR taps (essentially LFSRs) some old 8bit machines used for sound

std::mt19937 doesn't return random number [closed]

China☆狼群 提交于 2019-12-08 04:24:19
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I have the following piece of code: unsigned int randomInt() { mt19937 mt_rand(time(0)); return mt_rand(); }; If I call this code, for example 4000 times in a for loop, I don't get random unsigned integers, instead I get for example 1000 times one value and the next 1000 times I get the next value. What am I

What makes the Mersenne Twister Tempering function reversible?

流过昼夜 提交于 2019-12-07 10:31:06
问题 It is well known that it is possible to reverse the MT tempering function. Source code is available online to do this here. I'm trying to figure how this works and how I would approach this and similar problems in a programmatic fashion. What I'm struggling with is that shift operations on a variable of finite size should result in irreversible data loss. Similarly, the bit-wise AND operations should also result in permanent data loss, yet the sample code provided can reverse any value to it

What is the difference between using std::random_device with pRNG e.g. std::mt19937 and without?

瘦欲@ 提交于 2019-12-07 09:38:00
问题 In C++11 one can generate numbers with the use of std::random_device with or without a pseudo random number generator like mt19937. What will be the difference using this in this exemplar code: #include <random> #include <iostream> int main() { std::random_device rd; std::mt19937 mt(rd()); std::uniform_real_distribution<double> dist(1, 10); for (int i=0; i<16; ++i) std::cout << dist(rd) << "\t" << dist(mt) << "\n"; } 回答1: std::random_device is supposed to get you a seed for engines like

Random access encryption with AES In Counter mode using Fortuna PRNG:

梦想的初衷 提交于 2019-12-07 04:43:59
问题 I'm building file-encryption based on AES that have to be able to work in random-access mode (accesing any part of the file). AES in Counter for example can be used, but it is well known that we need an unique sequence never used twice. Is it ok to use a simplified Fortuna PRNG in this case (encrypting a counter with a randomly chosen unique key specific to the particular file)? Are there weak points in this approach? So encryption/decryption can look like this Encryption of a block at Offset