# What's the problem of using the clock to generate random numbers?

If the clock shows 14:15:36.909302, why not just use the fractions of a second part (09302) as a kind of random number?

What is wrong with this form of generating random numbers?

I am aware that obtaining truly random numbers is a difficult task, so I am assuming that there is something wrong with this method.

• What research have you done? There is lots written on this subject.
– D.W.
Dec 31, 2013 at 22:09

1. If the run time of your algorithm to pick a random number is not random you could get a pattern of times which is not random.

As an example. Suppose the function to read the time is triggered by an event, and the event is timed to the clock, now your functions based on the clock.

2. If the run time of your algorithm is faster than the precision of the clock, then you will get duplicate times and thus duplicate numbers which are not random.

As an example. You write a function for use by others, and someone decides to generate 10,000 random numbers and store them. The loop is so tight for reading the clock and saving the values that you get 10,000 numbers all identical.

These are just cases that can make the data non-random. In reality if it is not security related I run a large sample through a test for randomness and if it were reasonable I would use it, but if it is security related I would ask at Security or Crypto

• You may add that the execution speed is often indeterministic whereas it is often desirable to have a reproducible random generator.
– Val
Dec 31, 2013 at 22:41
• Jul 11, 2014 at 11:45

If you use a clock to generate a number for a roulette machine then every hour you will have 3600 seconds to use as your seed number,multiply this seed number by the same fixed number every second and you will produce a different number every second. If you make the fixed number the date then every day you will get a different sequence of numbers,even better,if you started with pi at the very beginning then the very last 4 digits could be your fixed number as pi never repeats a sequence? The number generated would be the last digit of the equation,as long as it is between Zero and 37,if it outside this range it gets disguarded and the next number used,if there are a few numbers in succession that fall outside our scale then this is when you get repeat numbers or zero!!! Any thoughts?

• Please use paragraphs and notation to explain your problem better. Apr 29, 2018 at 10:23
• By "pi never repeats a sequence", I guess you mean that pi is irrational so it's not a repeating decimal (e.g., 3.141592659265926...)? Jan 13, 2019 at 0:39