+ 5
How to get truly random number using random module????......in python actually :p
7 odpowiedzi
+ 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.
+ 13
#assuming you mean in python
import random
var=random.randint(0,666)
#var is = to number between 0 and 666
print(var)
+ 12
See my code. There is random number generated with time in milliseconds.
https://code.sololearn.com/c5WOOXcCA19L/?ref=app
+ 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
+ 7
one: we need to know your language
+ 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.
+ 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.