Generally, computers use mathematical algorithms to supply random numbers, but
those numbers are pseudo-random. That is because the algorithms
implement mathematical formulae which are deterministic: the
resulting sequence of numbers is determined by the seed value input to the
formula, and it is always the same for a given seed value. An
approach to overcome this predictability has been to derive “entropy”
from the hardware on which the program is running, by using numerical
inputs derived from fan noise, mouse movements, keyboard timings,
etc. The idea is to aggregate entropy from several unrelated sources,
to ensure true randomness. However, the author has found that one
source of entropy, the human-to-computer interface, provides
sufficient entropy to ensure randomness for a number generated within
a range delimited by a power of 2, such as 0 to 63, in response to a
mouse click.
Modern CPUs in personal computers and business servers have a TSC (Time Stamp Counter), a 64-bit register that is incremented at a constant rate, typically 3 gigahertz. The rate at which the TSC is incremented does not vary, while the rate of the CPU clock does vary in response to computational demand and thermal regulation. When human input occurs in the form of a mouse click, a hardware interrupt request is sent to the CPU, which responds to the interrupt at the end of execution of the current instruction. That and previous instructions typically take one to several CPU clock cycles to execute. The processing of an interrupt request is asynchronous with the instantaneous count in the TSC, and the time at which a human impulse to click the mouse occurs is unrelated to the timing of events in computer hardware. To draw an analogy, clicking the mouse is like throwing a dart at a wheel divided into 64 segments labeled 0 through 63, spinning at 46,875,000 revolutions per second. Hence, a number sampled from the low-order bits of the TSC, in response to a click of the mouse, is random.
The low-order binary digits or “bits” of the TSC function as a counter that cycles rapidly through a range determined by the number of bits. For example, the six least significant bits of the TSC comprise a repeat cycle counter having the range 0‒63. Incremented at 3 GHz, the count from 0 to 63 repeats 46,875,000 times per second. The interval of time from one mouse click to the next is not determined by machine but by consciousness expressed through the biological processes involved in clicking the mouse. The decision to click the mouse and the execution of that command via the nervous system and muscles is very irregular and imprecise in terms of the clock rate of the TSC, which is regular and precise. Randomness is inherent in that irregular and temporally imprecise sampling of a regular and precise process running at high speed. The entropy of the human-to-computer interface via the mouse is compounded by the entropy of the asynchronous relation of the TSC to the variable clock speed and instruction cycle length of the CPU.
A random number in the range 0–63 is derived by sampling the value of the six least significant bits of the TSC when a mouse click is processed. Zero corresponds to all six bits having the value 0, and 63 corresponds to all six bits having the value 1. Therefore, the range 0–63 encompasses all possible combinations of zeros and ones for those six bits, and each combination has an equal probability of existing at the time of sampling. Because a discrete number of bits is sampled, the upper limit of the range represented by those bits is always a power of 2, minus 1. For example, 26 equals 64, the maximum number of states that can be represented by 6 bits. Because one of those states is 0, the maximum number that can be represented by 6 bits is 63.
Fewer or more bits could be sampled, for other ranges delimited by a power of 2. For example, sampling the four least significant bits provides a range of 0–15, and values in that range could be represented by a hexadecimal digit in the range 0–F. An arbitrarily large random number could be assembled by stringing hexadecimal digits together, using a succession of mouse clicks to generate each digit randomly. The following table shows ranges of values corresponding to number of bits.
| Bits | Range |
|---|---|
| 1 | 0–1 |
| 2 | 0–3 |
| 3 | 0–7 |
| 4 | 0–15 |
| 5 | 0–31 |
| 6 | 0–63 |
| 7 | 0–127 |
| 8 | 0–255 |
| 9 | 0–511 |
| 10 | 0–1023 |
Sampling more than 16 bits for this algorithm risks compromising the random nature of the generated result. At 3 MHz, the count from 0 to 65,535 repeats 45,776 times per second, fast enough to be asynchronous with whatever precision a rapid, regular succession of mouse clicks might have. Intuitively, sampling more than 16 bits runs counter to the goal of randomness. It is better to obtain a large random number by assembling many samples of fewer bits, rather than a few samples of many bits.
What if the desired range is not delimited by a power of 2? There is no mathematical way, that preserves randomness, to impose an upper limit that is not represented by all bits having the value 1. Mapping values outside the desired range to numbers inside the range would skew the probabilities higher for numbers mapped to numbers outside the range. However, numbers occurring outside the desired range can simply be discarded, and the mouse can be clicked again, until a number in the desired range occurs. Zero could be excluded from the desired range by discarding it, or by adding 1 to each generated number. In that way, the range 0–63 becomes 1–64. Discarding numbers outside the desired range works because a range of numbers within a set of random numbers is also random.
A computer program that implements this non-mathematical algorithm for generating true random numbers is TrueRand, available in Microsoft Store.
Copyright 2025 Steven A. Brown