lcg

Linear congruential generator - how to choose seeds and statistical tests

一笑奈何 提交于 2021-01-27 12:21:41
问题 I need to do a linear congruential generator that will successfully pass the selected statistical tests. My question is: how to choose numbers for the generator properly and which statistical tests should I choose? I thought about: Chi-Square Frequency Test for Uniformity Collect 10,000 numbers per generation method Sub-divide[0.1) into 10 equal subdivisions Kolmogorov-Smirnov Test for uniformity Since K-S Test works better with a smaller set of numbers, you may use the first 100 out fo the

pseudo random distribution which guarantees all possible permutations of value sequence - C++

让人想犯罪 __ 提交于 2019-12-19 08:33:09
问题 Random question. I am attempting to create a program which would generate a pseudo-random distribution. I am trying to find the right pseudo-random algorithm for my needs. These are my concerns: 1) I need one input to generate the same output every time it is used. 2) It needs to be random enough that a person who looks at the output from input 1 sees no connection between that and the output from input 2 (etc.), but there is no need for it to be cryptographically secure or truly random. 3

Making a customizable LCG that travels backward and forward

寵の児 提交于 2019-12-11 00:29:32
问题 How would i go about making an LCG (type of pseudo random number generator) travel in both directions? I know that travelling forward is (a*x+c)%m but how would i be able to reverse it? I am using this so i can store the seed at the position of the player in a map and be able to generate things around it by propogating backward and forward in the LCG (like some sort of randomized number line). 回答1: All LCGs cycle. In an LCG which achieves maximal cycle length there is a unique predecessor and

why 48 bit seed in util Random class?

余生长醉 提交于 2019-12-06 21:15:48
问题 Why this class uses 48 bit seed in its linear congruence formula? I would have expected 32 or 64... I know it takes higher order bits when asked for 32 bit values. But why only 16 more additional bits? Was it a "random" choice? 回答1: You need more bits of state than bits of output, because the nature of an LCG is such that the low-order bits of state are not very random at all. So if you want 32-bit outputs, you need more than 32 bits of state. Why use 48 rather than 64? Because 48 is enough,

why 48 bit seed in util Random class?

99封情书 提交于 2019-12-05 02:35:47
Why this class uses 48 bit seed in its linear congruence formula? I would have expected 32 or 64... I know it takes higher order bits when asked for 32 bit values. But why only 16 more additional bits? Was it a "random" choice? You need more bits of state than bits of output, because the nature of an LCG is such that the low-order bits of state are not very random at all. So if you want 32-bit outputs, you need more than 32 bits of state. Why use 48 rather than 64? Because 48 is enough, and you're designing this decades ago , so there are good reasons to want to avoid using any more resources

How to generate a predictable shuffling of a sequence without generating the whole sequence in advance?

…衆ロ難τιáo~ 提交于 2019-11-29 04:01:58
问题 The following python code describes exactly what I want to achieve for a sequence of arbitrary size (population): import random fixed_seed = 1 #generate the same sequence every time with a fixed seed population = 1000 sample_count = 5 #demonstration number num_retries = 3 #just enough to show the repeatable behaviour for trynum in xrange(num_retries): #generate the fresh/ordered sequence (0->population)... seq = range(population) #seed the random number generator the same way every time...

Why is the use of rand() considered bad?

*爱你&永不变心* 提交于 2019-11-26 17:08:41
问题 I heard some guys telling that the use of rand() is bad EVEN AFTER USING srand() to get a seed. Why is that so? I want to know how the stuff happens... And sorry for another question.. but what is an alternative to this then? 回答1: There are two parts to this story. First, rand is a pseudorandom number generator. This means it depends on a seed. For a given seed it will always give the same sequence (assuming the same implementation). This makes it not suitable for certain applications where