+ 2
How do people make random numbers from scratch?
Or even an illusion. How is it possible to generate seemingly random numbers from scratch? Not going to implement, just curious.
8 Réponses
+ 5
It's usually based on the current time, processed though and algorithm to generate a seemingly random number.
+ 5
Divya Mohan I said how to do it from scratch. No shortcuts
+ 2
This looks like the source code for a random number in java, http://developer.classpath.org/doc/java/util/Random-source.html. I do see a call to get the system time in milliseconds.
+ 2
A question, I saw that you can make pure random numbers with seeds. What are they?
+ 2
Pseudo random number generators use a seed such as time... Pseudo because it can be easily replicated. True random number generators use other hardware with sensors less likely to be replicated, such as temperature, atmospheric pressure, radiation, magnetic field as their seed(s).
+ 2
I started experimenting with one technique- linear congruential generator, but I never finished evaluating its randomness. I studied information from several sources - textbooks, old HP-41 calculator source code, and Wikipedia. The method is customizable by adjusting constants, but each change should be evaluated for apparent randomness, else patterns and bias easily creep in.
https://code.sololearn.com/c5Cgo15HcF98/?ref=app
Here I used it in a histogram programming challenge:
https://code.sololearn.com/cD7ENBgvKBSl/?ref=app
One of the neatest techniques is to base it on intervals between ticks from background radiation received on a portable nuclear radiation detector. On the Commodore 64 the noise wave generator of the sound (SID) chip was often used.
0
In js you can just use the method
Math.random()
To see result
console.log(Math.random()) ;
Refresh page to get each time new number btwn 0 and 1