so although using srand(time(0)) can be used to get truly random numbers, how truly random are they? For example, if one were to call this method at the same time (in this example, if one were to use this command at 51s) each time would the numbers generated be the same??? If so, are the numbers still truly random?? And if this theory is true, how can one generate truly random numbers that cannot repeat based on external variables (e.g., time)? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

so although using srand(time(0)) can be used to get truly random numbers, how truly random are they? For example, if one were to call this method at the same time (in this example, if one were to use this command at 51s) each time would the numbers generated be the same??? If so, are the numbers still truly random?? And if this theory is true, how can one generate truly random numbers that cannot repeat based on external variables (e.g., time)?

Using srand(time(0)) -- does calling this at the same time of day or time of computer runtime result in same random number(s)?

17th Aug 2016, 10:01 AM
Jason Zeleny
Jason Zeleny - avatar
4 Answers
+ 8
srand gives you pseudo-random numbers. They are not truly random. For truly random numbers one has to have a source of events that is unpredictable. As far as I know there are companies that provide(d) special hardware that generates truly random numbers from the random nature of atomic decay.
17th Aug 2016, 10:31 AM
Stefan
Stefan - avatar
+ 3
Let me add to my last answer. Pseudo-random numbers can be made less predictable than in your example. SSH uses user input and multiple computer system events to generate the (pseudo-)random numbers required for the SSH keys.
17th Aug 2016, 11:45 AM
Stefan
Stefan - avatar
0
Gotcha, thanks for the info!
17th Aug 2016, 12:36 PM
Jason Zeleny
Jason Zeleny - avatar
0
My pleasure, Jason :-)
17th Aug 2016, 1:40 PM
Stefan
Stefan - avatar