How to get truly random number using random module????......in python actually :p | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

How to get truly random number using random module????......in python actually :p

22nd Apr 2017, 11:14 AM
subhadeep chatterjee
subhadeep chatterjee - avatar
7 Answers
+ 15
@Thanh Le I heard there is a way to get truly random numbers by taking input from random noise in a microphone. I don't remember the specifics, but it still generated random even with the same sounds playing.
22nd Apr 2017, 12:46 PM
Ahri Fox
Ahri Fox - avatar
+ 13
#assuming you mean in python import random var=random.randint(0,666) #var is = to number between 0 and 666 print(var)
22nd Apr 2017, 11:21 AM
Ahri Fox
Ahri Fox - avatar
+ 12
See my code. There is random number generated with time in milliseconds. https://code.sololearn.com/c5WOOXcCA19L/?ref=app
22nd Apr 2017, 5:20 PM
Yasar Curci
Yasar Curci - avatar
+ 7
As support only (only intended to emphasize "truly random"/noise sources in other answers, not a full answer alone)--this code pulls from 'atmospheric noise': The source is random.org. It could be converted to another language; the point is that @Ahri Fox and @Thanh Lee are in the right areas. https://code.sololearn.com/WxkraG1imWtm/?ref=app
22nd Apr 2017, 1:18 PM
Kirk Schafer
Kirk Schafer - avatar
+ 7
one: we need to know your language
23rd Apr 2017, 4:52 AM
DeleteThisAccount
+ 6
It depends on what you mean with "truly random" number. But most likely the answer is no. You can't get a "truly random" number, because on a completely deterministic machine, like a computer, you can’t generate anything you could really call a random sequence of numbers.
22nd Apr 2017, 11:50 AM
Thanh Le
Thanh Le - avatar
+ 5
you can seed the random function with the current time in milliseconds when the function is called. It would be almost impossible to guess. Using the value of an analog input as ahri fox suggested could add complexity to guessing but can easily be overcome. The best solution would be to read the input from a floating (not pulled high/low) analog input that will act as an antenna catching every kind of electromagnetic signal.
22nd Apr 2017, 3:59 PM
seamiki
seamiki - avatar