How do people make random numbers from scratch? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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.

31st Jul 2020, 12:50 PM
Clueless Coder
Clueless Coder - avatar
7 Answers
+ 5
It's usually based on the current time, processed though and algorithm to generate a seemingly random number.
31st Jul 2020, 1:01 PM
Wubba Lubba Dub Dub
Wubba Lubba Dub Dub - avatar
+ 5
Divya Mohan I said how to do it from scratch. No shortcuts
31st Jul 2020, 1:07 PM
Clueless Coder
Clueless Coder - avatar
+ 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.
31st Jul 2020, 1:15 PM
Wubba Lubba Dub Dub
Wubba Lubba Dub Dub - avatar
+ 2
A question, I saw that you can make pure random numbers with seeds. What are they?
31st Jul 2020, 6:09 PM
Clueless Coder
Clueless Coder - avatar
+ 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).
31st Jul 2020, 7:24 PM
Wubba Lubba Dub Dub
Wubba Lubba Dub Dub - avatar
+ 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.
1st Aug 2020, 2:04 AM
Brian
Brian - avatar
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
31st Jul 2020, 1:02 PM
Divya Mohan
Divya Mohan - avatar