prng

Incorporating boost random number generator as a class variable

孤街醉人 提交于 2021-01-28 06:55:06
问题 I'm trying to create a wrapper class for the boost random number generator, based on http://www.sitmo.com/article/generating-random-numbers-in-c-with-boost/. The problem is that boost uses templates and I don't know how to separate the declaration of GEN gen from the instantiation, like what can be done with separating DIST dist from dist = DIST(0, 1) . Any advice appreciated. fr.hpp: #include <boost/random/variate_generator.hpp> #include <boost/generator_iterator.hpp> #include <boost/random

C++ thread-safe uniform distribution random number generation

大城市里の小女人 提交于 2020-06-11 03:58:46
问题 I have a loop. Inside the loop, in each iteration, I need to draw a number from U[0,1]. How can I use openmp, and also make sure that the random number generating process is not contaminated? I got suggestion that I need a thread-safe random number generator, which may or may not be the solution to my problem. My question is very related to another one, with a slight difference that I want to draw from a coninuum U[0,1]. Additionally, I don't know how to seed generator by thread, can someone

Scaling Int uniform random range into Double one

我与影子孤独终老i 提交于 2020-01-06 05:09:06
问题 Actually, I have several interweaving questions. (If it matters I use C#.) First. I have a prng that generates random numbers in UInt32 range, from 0 to UInt32.Max inclusive. I want to preserve the uniformity as much as possible. What is the main idea to get [a,b], (a,b) double ranges (such as [0,1], [0,1), (0,1), [-2,4], (-10,10))? I'm concerned about the following. I have 4 294 967 296 prng outcomes. It is less than numbers in [0,1] double range — 2^53. So I construct 4 294 967 296-ary

Cycle of SecureRandom of Java

ぃ、小莉子 提交于 2020-01-02 04:36:06
问题 PRNGs usually have a cycle after which the generated random numbers do repeat. What's the cycle of SecureRandom of Java when the instance of SecureRandom is created as follows: SecureRandom random = SecureRandom.getInstance("SHA1PRNG"); 回答1: I'm a bit confused. I had a look into the code of sun.security.provider.SecureRandom of the openjdk. Here the internal state is updated as follows: digest.update(state); output = digest.digest(); updateState(state, output); [...] private static void

Is Ruby's seed for OpenSSL::Random sufficient?

最后都变了- 提交于 2020-01-02 02:08:07
问题 I know very little about Ruby, so please forgive me if the answer to this is obvious. I noticed at http://www.ruby-doc.org/stdlib-1.9.3/libdoc/securerandom/rdoc/SecureRandom.html that Ruby uses the pid and the current time to seed OpenSSL::Random when a call to random_bytes is made. Unless something else happens under the covers, isn't this pretty much the seed that Netscape used in their initial SSL implementation in the mid 90s? http://en.wikipedia.org/wiki/Random_number_generator_attack

Is there “good” PRNG generating values without hidden state?

独自空忆成欢 提交于 2020-01-01 09:25:17
问题 I need some good pseudo random number generator that can be computed like a pure function from its previous output without any state hiding. Under "good" I mean: I must be able to parametrize generator in such way that running it for 2^n iterations with any parameters (or with some large subset of them) should cover all or almost all values between 0 and 2^n - 1 , where n is the number of bits in output value. Combined generator output of n + p bits must cover all or almost all values between

Pseudorandom generator in Assembly Language

ぐ巨炮叔叔 提交于 2019-12-30 06:49:17
问题 I need a pseudorandom number generator algorithm for a assembler program assigned in a course, and I would prefer a simple algorithm. However, I cannot use an external library. What is a good, simple pseudorandom number generator algorithm for assembly? 回答1: Easy one is to just choose two big relative primes a and b, then keep multiplying your random number by a and adding b. Use the modulo operator to keep the low bits as your random number and keep the full value for the next iteration.

Using engines for random number generation

安稳与你 提交于 2019-12-24 04:58:05
问题 I am trying to use the RAND_bytes API of OpenSSL, but I want to try it with various Random Number Generating Engines. Is there a recommended way of generating Random bytes and adding entropy in OpenSSL? Where can I get other Engine implementations, and how can I swap them in? 回答1: Is there a recommended way of generating Random bytes and adding entropy in OpenSSL? Yes. See the OpenSSL wiki on Random Numbers. It takes you through adding entropy for a seed, and extracting bytes for use in

Java Random seed

余生颓废 提交于 2019-12-24 00:42:14
问题 I need to test out a Java program 20 times and need to set the random seed so that the tests can be repeated. If I were to set the initial seed as 0 and then increment by 1 at each run (i.e. 1,2,3 etc), would this method still ensure complete randomness, even though the seeds are not far apart? Thank you 回答1: Any seed will provide the same level of randomness as any other seed for a standard PRNG like the one included with Java. So it's fine to use an incrementing seed for tests. You might

Cross-platform cross-language cross-everything actually deterministic random number generator

北城余情 提交于 2019-12-23 20:00:24
问题 I'm looking for an algorithm to generate random numbers from a given seed but with the particular requirement that it will always generate the same sequence of number regardless of the underlying computer architecture or language implementation. I already know of Mersenne Twister, however, the numbers it generates differ when using different implementations (i.e. C MT vs Javascript MT). Do algorithms with this property exist? Also, I don't need a state-of-the-art RNG, I don't even need it to