Randomness and Generators

Period Length and Repeating Sequences in Generators

Every algorithmic random number generator eventually repeats. See what period length means, why modern generators make repetition irrelevant, and where it can matter.

On this page
  1. Why repetition is unavoidable
  2. A tiny example
  3. How big is big enough?
  4. Period is not the whole story
  5. Where period can still matter
  6. What players can and cannot infer

Slot-style games are games of chance with a built-in house edge. No strategy, system or timing changes the odds, most players lose money over time, and nobody should gamble money they cannot afford to lose. A recurring worry about computer-driven games is whether their random numbers “run out” and start repeating. The accurate answer is that every algorithmic generator does repeat eventually, but for good designs that moment is so far away it has no practical meaning.

Why repetition is unavoidable

A pseudorandom generator keeps an internal state, a fixed amount of stored data. Each step computes a new state from the old one using a deterministic rule, and the output comes from that state. If the state has only a finite number of possible values, then after enough steps the generator must land on a state it has visited before. From that point on, because the rule is deterministic, it replays the same sequence of states and outputs forever. The number of steps before the cycle restarts is the period.

A generator with a state of n bits has at most 2^n distinct states, so its period cannot exceed 2^n. This is a hard ceiling, set by how much memory the generator uses.

A tiny example

Take the hypothetical rule: next = (5 × current + 3) mod 16. Starting from 7, the sequence is 7, 6, 1, 8, 11, 10, 5, 12, 15, 14, 9, 0, 3, 2, 13, 4, then 7 again. That is 16 values before the loop, so the period is 16, which is the maximum possible with only 16 states. Anyone watching would see the pattern after one lap.

Not every rule achieves the maximum. A poor choice of constants can trap the generator in a short cycle, perhaps just a few values. Choosing the constants so the full cycle is used is part of the design work for older, simple generators.

How big is big enough?

Here is some simple arithmetic, again hypothetical.

  • A 32-bit state allows at most 2^32 = 4,294,967,296 states. At one million numbers per second, that is about 4,295 seconds, which is roughly 72 minutes, before a maximum-period generator repeats. That is short enough to matter in a heavy simulation.
  • A 64-bit state allows about 1.8 × 10^19 states. At one billion numbers per second, that is about 1.8 × 10^10 seconds, or roughly 585 years.
  • Widely used general-purpose generators go much further. The Mersenne Twister, a popular design, has a period of 2^19937 − 1, a number with about 6,000 decimal digits. Running it for the age of the universe would not use a measurable fraction of its cycle.

Once the period is far beyond any plausible number of draws, repetition is a theoretical fact rather than a practical concern. A slot-style game that draws numbers for years across many machines will still be nowhere near completing a cycle.

Period is not the whole story

A long period does not make a generator good. A generator could cycle through a huge number of states while producing output with obvious structure, such as alternating low and high values, or correlations between values a fixed distance apart. This is why statistical randomness tests examine more than repetition.

Nor does a long period make a generator unpredictable. The Mersenne Twister, for example, has a very long cycle yet is not suitable for security uses, because observing a few hundred consecutive outputs allows its internal state to be reconstructed, after which every future value can be computed. Security-oriented designs add extra mixing so that output reveals little about state. The role of the starting value in all this is covered in the article on the seed value, and the distinction between types of generator appears in the comparison of true randomness with algorithmic output.

Where period can still matter

  • Parallel simulations. If many processes start the same generator from nearby seeds, their sequences might overlap, producing duplicated “independent” results. Libraries address this by splitting the cycle into separate streams.
  • Small embedded systems. Devices with very small state may have short periods, and careless design could expose them.
  • Reseeding mistakes. Restarting the generator from the same seed again and again replays the same sequence from the beginning, regardless of its period. That is a seeding error, not a period problem, but it looks like repetition to an observer.

What players can and cannot infer

The existence of a cycle does not give a player a way to exploit anything. To use it you would need to know the generator’s exact algorithm, its state at a given moment, and the precise timing and number of draws consumed by other activity, none of which an ordinary player can observe. Modern regulated games also tend to draw numbers continuously, so the position in the cycle at the time of any spin is, for practical purposes, unknowable. As with other myths, the idea that a machine “resets” or runs through a visible cycle is a case of the clustering illusion and belongs with the other randomness misconceptions. Each result is still independent of the last from the player’s perspective, and the long-run return to player is a statistical average, not a schedule.

If you gamble, set limits on money and time beforehand, treat it as paid entertainment, never chase losses, and take regular breaks. If it starts to feel out of control, a national problem-gambling helpline or local health service can help. Gambling is age-restricted or illegal in many places, and rules differ by country.

The complete guide to randomness and generators

How Computers Generate Random Numbers
Read the guide

Keep exploring

Guides from other topics

All topics →