Answer the question
In order to leave comments, you need to log in
How to generate a random number in an interval?
How to programmatically generate REALLY close to random numbers in the range?
I read that for this they take several sources of random numbers - /dev/urandom, iron generators, send user mouse movements and mix together, and random numbers are generated based on this stream.
But... I don't know much about how to mix them? How to turn a random stream of bytes into a number on a segment so that it remains random enough?
Can you either explain or point the way to explore this issue?
Answer the question
In order to leave comments, you need to log in
You collect all the entropy bit by bit (paravozik) into one message. Take a hash function with a suitable size and distribution, like MD5 , and run the message through it. At the output, get a uniformly distributed random 128-bit number. That is, from 0 to (2^128)-1 if represented unsigned. Divide (or take the remainder if integers are needed), add - you get the range you need.
PS: MD5 is here as an example, don't use it in harsh production, it's compromised. Choose a hash function with a number of internal states that matches the intended entropy length.
Oh, what difficulties. And they didn’t teach you how to take the rest? And then add the bottom border.
You can mix any way you like. You can xor'it byte by byte, you can add, you can multiply. By the way, byte xor is probably the best way to shuffle. Only it is byte-by-byte and gives perhaps the best distribution.
Well, numbers are stored in a peculiar pool of bytes. You can ask for one (char), two (short) or four (int) bytes from this pool and it will be within its own limits. How to convert a random number to a number in the desired range, see below:
Number RandomBeetwen(Number min, Number max):
return min + Random() % (max - min);
I read that for this they take several sources of random numbers - /dev/urandom, iron generators, send user mouse movements and mix together ... I don't know much about how to mix them?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question