Let's say I got three pseudo random numbers from different pseudo random number generators. Since the generators would reflect only a part of the real random number generating process, I believe that one way to get a number closer to real random might be to somehow get a "center" of the three pseudo random numbers. An easy way to get that "center" would be to take average, median or mode (if any) of them. I am wondering if there's a more sophisticated way due to the fact that they should represent random numbers.
-
taking average results in less randmness actually,, since randomness is in a sense equjivalent to high entropy (aka high frequencies) whereas averaging (or median or similar) results in lowpass filtering which excludes high frequencies, thus less entropy on average – Nikos M. May 01 '20 at 17:10
-
instead an easy techineque to use it to choose at random one number from the list of random numbers. – Nikos M. May 01 '20 at 17:12
-
What programming language are you using? – Peter O. May 01 '20 at 17:42
-
I can use almost any programming language for this. So please let me know your suggestion regardless of language. – user1586400 May 02 '20 at 00:38
3 Answers
Trying to use some form of "centering" turns out to be a bad idea if your goal is to have a better representation of the randomness.
First, a thought experiment. If you think three values gives more randomness, wouldn't more be even better? It turns out that if you take either the average or median of n Uniform(0,1) values, as n→∞ these both converge to 0.5, a point. It also happens to be the case that replacing distributions with a "representative" constant is generally a bad idea if you want to understand stochastic systems. As an extreme example, consider queues. As the arrival rate of customers/entities approaches the rate at which they can be served, stochastic queues get progressively larger on average. However, if the arrival and service distributions are constant, queues remain at zero length until the arrival rate exceeds the service rate, at which point they go to infinity. When the rates are equal, the stochastic queue would have infinite queues, while the deterministic queue would remain at its initial length (usually assumed to be zero). Infinity and zero are about as wildly different as you can get, illustrating that replacing distributions in a queueing model with their means would give you no understanding of how queues actually work.
Next, empirical evidence. Below histograms of the medians and averages constructed from 10,000 samples of three uniforms. As you can see, they have different distribution shapes but are clearly no longer uniform. Values bunch in the middle and are progressively rarer towards the endpoints of the range (0,1).
The uniform distribution has maximum entropy for continuous distributions on a closed interval, so both of these alternatives, being non-uniform, are clearly lower entropy, i.e., more predictable.

- 18,696
- 4
- 27
- 56
-
Thank you very much for both of the explanation method! So it is not a good idea to get a "representative" value at all. – user1586400 May 02 '20 at 00:38
-
You're welcome. You can always upvote answers that you find helpful, or even mark them as "the answer" if you believe that to be the case. – pjs May 02 '20 at 02:01
Well, there is an approach, called entropy extractor, which allows to get (good) random numbers from not quite random source(s).
If you have three independent but somewhat low quality (biased) RNGs, you could combine them together into uniform source.
Suppose you have three generators giving you a single byte each, then uniform output would be
t = X*Y + Z
where addition and multiplication are done over GF(28) finite field.
Some code (Python)
def RNG1():
return ... # single random byte
def RNG2():
return ... # single random byte
def RNG3():
return ... # single random byte
from pyfinite import ffield
def muRNG():
X = RNG1()
Y = RNG2()
Z = RNG3()
GF = ffield.FField(8)
return GF.Add(GF.Multiply(X, Y), Z)
Paper where this idea was stated

- 18,636
- 3
- 38
- 64
To get good random numbers, it's advisable to get some bits of entropy. Depending on whether they are used for security purposes or not, you could just get the time from the system clock as a seed for a random number generator, or use more sophisticated means. The project PWGen download | SourceForge.net is open-sourced, and monitors Windows events as a source of random bits of entropy.
You can find more info on how to random numbers in C++ from this SO ? too: Random number generation in C++11: how to generate, how does it work? [closed]. It turns out C++'s random numbers aren't always all that random: Everything You Never Wanted to Know about C++'s random_device; so looking for a good way to seed, i.e. by passing the time in mS to srand()
and calling rand()
might be a quick and dirty way to go.

- 1,248
- 13
- 22