# How was randomness achieved in older video games?

**URL:** https://boards.straightdope.com/t/how-was-randomness-achieved-in-older-video-games/741023
**Category:** Factual Questions
**Created:** [December 21, 2015, 8:25pm UTC](https://boards.straightdope.com/t/how-was-randomness-achieved-in-older-video-games/741023 "2015-12-21T20:25:49Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![gracefulfatsheba](https://avatars.discourse-cdn.com/v4/letter/g/a3d4f5/32.png) [@gracefulfatsheba](https://boards.straightdope.com/u/gracefulfatsheba)
#### Post date: [December 21, 2015, 8:25pm UTC](https://boards.straightdope.com/t/how-was-randomness-achieved-in-older-video-games/741023/1 "2015-12-21T20:25:49Z")

</div>

In some older video games, the behavior of enemies or the results of given actions appear to be randomly decided and unpredictable.

How was this achieved on a technical level? These old video game consoles (1980s and before) didn’t have internal system clocks, which I believe is how ‘random’ numbers and such are generated with code these days.

How is it that a video game from the 1980s, on a system with no internal clock and given the same inputs, could achieve a random result?

---

<div class="post-metadata">

### Author: ![Unpronounceable](https://avatars.discourse-cdn.com/v4/letter/u/9de0a6/32.png) [@Unpronounceable](https://boards.straightdope.com/u/Unpronounceable)
#### Post date: [December 21, 2015, 8:30pm UTC](https://boards.straightdope.com/t/how-was-randomness-achieved-in-older-video-games/741023/2 "2015-12-21T20:30:21Z")

</div>

The “easy” way was just to capture the milliseconds from the clock.

---

<div class="post-metadata">

### Author: ![The\_Hamster\_King](https://avatars.discourse-cdn.com/v4/letter/t/8edcca/32.png) [@The\_Hamster\_King](https://boards.straightdope.com/u/The_Hamster_King)
#### Post date: [December 21, 2015, 8:36pm UTC](https://boards.straightdope.com/t/how-was-randomness-achieved-in-older-video-games/741023/3 "2015-12-21T20:36:52Z")

</div>

Then and now, random numbers are generated with pseudorandom number generators – i.e. recursive numeric functions that produce output values that look random even through they’re deterministic.

Often the pseudorandom number generator is “seeded” with a value from the system clock to prevent it running through the same sequence every time you start the game. But you can use any sort of noise as the seed, including player inputs.

---

<div class="post-metadata">

### Author: ![Jragon](https://avatars.discourse-cdn.com/v4/letter/j/e19b73/32.png) [@Jragon](https://boards.straightdope.com/u/Jragon)
#### Post date: [December 21, 2015, 8:43pm UTC](https://boards.straightdope.com/t/how-was-randomness-achieved-in-older-video-games/741023/4 "2015-12-21T20:43:28Z")

</div>

[Here’s an article from 1989 about Atari RNGs](http://www.atarimagazines.com/v7n11/randomatari.html)

Apparently:

> [@](#):
>
> The Atari 8-bit computer has excellent random number generator. In fact, its biggest drawback is that the numbers it produces are too random!
> 
> Random numbers are generated on the Atari by measuring random noise on an electronic circuit, and converting this to a value between zero and 65,535. This is divided by 65,536, to give a value between zero and one. These are excellent random numbers but they are non-repeatable. If you run a program whose results depend on random numbers, you will never be able to repeat those same results.

This is actually the way Linux’s /dev/random works. Interestingly, this is a true RNG and not a pseudo-random generator like clock-based systems (which use the current system time as a seed).

The downside to this method is that if you’re requesting too many bits of randomness, there may not be enough information to provide a number, however, this is unlikely to be an issue given the relatively low complexity of Atari games. If it is an issue, you can always use a single random number from the system noise to seed a pseudo-random generator.

> [@The\_Hamster\_King](#):
>
> But you can use any sort of noise as the seed, including player inputs.

Well, until the speedrunners get a hold of your game. 😉

---

<div class="post-metadata">

### Author: ![Lemur866](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lemur866/32/434_2.png) [@Lemur866](https://boards.straightdope.com/u/Lemur866)
#### Post date: [December 21, 2015, 8:45pm UTC](https://boards.straightdope.com/t/how-was-randomness-achieved-in-older-video-games/741023/5 "2015-12-21T20:45:59Z")

</div>

And very often behavior of the game that appeared random was not random at all. Lots of old games were “beat” when people discovered that if they always took exactly the same actions, the enemies would always do exactly the same thing, and that the only randomness was that introduced by the player.

---

<div class="post-metadata">

### Author: ![Jragon](https://avatars.discourse-cdn.com/v4/letter/j/e19b73/32.png) [@Jragon](https://boards.straightdope.com/u/Jragon)
#### Post date: [December 21, 2015, 8:51pm UTC](https://boards.straightdope.com/t/how-was-randomness-achieved-in-older-video-games/741023/6 "2015-12-21T20:51:15Z")

</div>

Oh, and keep in mind that “clock” doesn’t necessarily mean “clock” as you know it. RNG seeds aren’t looking for a “clock” that says right now it’s December 21, 2015 at 12:52 PST, they’re generally looking at the system clock which measures things like how many CPU cycles have passed, how long the system has been booted up, and stuff like that.

---

<div class="post-metadata">

### Author: ![beowulff](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/beowulff/32/542_2.png) [@beowulff](https://boards.straightdope.com/u/beowulff)
#### Post date: [December 21, 2015, 9:01pm UTC](https://boards.straightdope.com/t/how-was-randomness-achieved-in-older-video-games/741023/7 "2015-12-21T21:01:12Z")

</div>

> [@Jragon](#):
>
> Oh, and keep in mind that “clock” doesn’t necessarily mean “clock” as you know it. RNG seeds aren’t looking for a “clock” that says right now it’s December 21, 2015 at 12:52 PST, they’re generally looking at the system clock which measures things like how many CPU cycles have passed, how long the system has been booted up, and stuff like that.

A good source of randomness is the measure the time from boot to first user input.  
This will only very rarely be the same from boot to boot.

---

<div class="post-metadata">

### Author: ![engineer\_comp\_geek](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/engineer_comp_geek/32/504_2.png) [@engineer\_comp\_geek](https://boards.straightdope.com/u/engineer_comp_geek)
#### Post date: [December 21, 2015, 9:14pm UTC](https://boards.straightdope.com/t/how-was-randomness-achieved-in-older-video-games/741023/8 "2015-12-21T21:14:24Z")

</div>

A lot of 8 bit systems had a clock tick that was tied to the video vertical refresh rate (which varied slightly between PAL and NTSC systems). The Commodore 64 called theirs a “jiffy clock” and you could measure time by counting “jiffies”.

Since these clocks tended to be down in the millisecond range, you could generate a fairly random 8 bit number fairly easily just by measuring how long it took someone to press the start button for the game. That gives you a fairly random number to use as a seed value, which you can then shove into a pseudorandom sequence generator to create your “random” numbers.

The Commodore 64 also had a hardware random number generator, similar to the previously mentioned Atari. The Commodore had a sound chip that they called SID (for Sound Interface Device) that was a fairly primitive sound synthesizer. It had four modes of operation: sine wave, square wave, sawtooth wave, and noise. SID had a built-in A/D converter that could convert the noise signal into a digital random number.

The Commodore 64 also had a pseudorandom sequence generator built into its ROM. You started with your seed value, and every call to that particular ROM subroutine would return the next number in the pseudorandom sequence. You could use the jiffy count method to generate your seed, or you could use the SID hardware method to generate your seed, or you could put in a known integer value as your seed so that you got the same sequence every time (useful for debugging).

Most 8 bit machines did not have a hardware random number generator built into them and instead relied on things like clock tick counting to generate their random seeds.

---

<div class="post-metadata">

### Author: ![Kinthalis](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/kinthalis/32/16084_2.png) [@Kinthalis](https://boards.straightdope.com/u/Kinthalis)
#### Post date: [December 21, 2015, 9:26pm UTC](https://boards.straightdope.com/t/how-was-randomness-achieved-in-older-video-games/741023/9 "2015-12-21T21:26:00Z")

</div>

How did they “measure random noise in an electronic circuit” in the Atari? Was this dedicated hardware?

---

<div class="post-metadata">

### Author: ![gracefulfatsheba](https://avatars.discourse-cdn.com/v4/letter/g/a3d4f5/32.png) [@gracefulfatsheba](https://boards.straightdope.com/u/gracefulfatsheba)
#### Post date: [December 21, 2015, 9:27pm UTC](https://boards.straightdope.com/t/how-was-randomness-achieved-in-older-video-games/741023/10 "2015-12-21T21:27:38Z")

</div>

> [@engineer\_comp\_geek](#):
>
> A lot of 8 bit systems had a clock tick that was tied to the video vertical refresh rate (which varied slightly between PAL and NTSC systems). The Commodore 64 called theirs a “jiffy clock” and you could measure time by counting “jiffies”.
> 
> Since these clocks tended to be down in the millisecond range, you could generate a fairly random 8 bit number fairly easily just by measuring how long it took someone to press the start button for the game. That gives you a fairly random number to use as a seed value, which you can then shove into a pseudorandom sequence generator to create your “random” numbers.
> 
> The Commodore 64 also had a hardware random number generator, similar to the previously mentioned Atari. The Commodore had a sound chip that they called SID (for Sound Interface Device) that was a fairly primitive sound synthesizer. It had four modes of operation: sine wave, square wave, sawtooth wave, and noise. SID had a built-in A/D converter that could convert the noise signal into a digital random number.
> 
> The Commodore 64 also had a pseudorandom sequence generator built into its ROM. You started with your seed value, and every call to that particular ROM subroutine would return the next number in the pseudorandom sequence. You could use the jiffy count method to generate your seed, or you could use the SID hardware method to generate your seed, or you could put in a known integer value as your seed so that you got the same sequence every time (useful for debugging).
> 
> Most 8 bit machines did not have a hardware random number generator built into them and instead relied on things like clock tick counting to generate their random seeds.

Thank you for this very interesting information!

---

<div class="post-metadata">

### Author: ![Atamasama](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/atamasama/32/12961_2.png) [@Atamasama](https://boards.straightdope.com/u/Atamasama)
#### Post date: [December 21, 2015, 10:08pm UTC](https://boards.straightdope.com/t/how-was-randomness-achieved-in-older-video-games/741023/11 "2015-12-21T22:08:48Z")

</div>

I’ve written video games as a hobby (since the early 90s) and I’ve used both system clock and player input as RNG seeds.

Both methods work pretty well, well enough that even though I wrote the code I couldn’t “trick” the system. I imagine it would be even more difficult to extrapolate the seed method through observation and then manipulate it.

---

<div class="post-metadata">

### Author: ![KarlGauss](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/karlgauss/32/3713_2.png) [@KarlGauss](https://boards.straightdope.com/u/KarlGauss)
#### Post date: [December 21, 2015, 10:14pm UTC](https://boards.straightdope.com/t/how-was-randomness-achieved-in-older-video-games/741023/12 "2015-12-21T22:14:38Z")

</div>

> [@Jragon](#):
>
> This is actually the way Linux’s /dev/random works. Interestingly, this is a true RNG and not a pseudo-random generator like clock-based systems (which use the current system time as a seed).
> 
> The downside to this method is that if you’re requesting too many bits of randomness, there may not be enough information to provide a number . . .

I’m not sure I follow. Do you mean that there wouldn’t have been sufficient time to generate the next random number?

---

<div class="post-metadata">

### Author: ![engineer\_comp\_geek](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/engineer_comp_geek/32/504_2.png) [@engineer\_comp\_geek](https://boards.straightdope.com/u/engineer_comp_geek)
#### Post date: [December 21, 2015, 10:19pm UTC](https://boards.straightdope.com/t/how-was-randomness-achieved-in-older-video-games/741023/13 "2015-12-21T22:19:46Z")

</div>

> [@Kinthalis](#):
>
> How did they “measure random noise in an electronic circuit” in the Atari? Was this dedicated hardware?

Atari had a chip called POKEY, which stood for Potentiometer/Keyboard interface. It also had sound capabilities. So yes, it was a dedicated hardware chip.

I didn’t know how POKEY actually did its thing as far as the random number generator was concerned, and I was curious, so I went poking (heh, sorry) around on the net. I was expecting maybe a reverse biased zener diode with the breakdown noise amplified and fed into an A/D converter, or something like that. I was rather surprised to find out that internally, POKEY used a linear feedback shift register to generate a pseudorandom sequence. So someone was lying. It wasn’t actually measuring random noise. It takes a long time for POKEY’s sequence to repeat, but it’s just a repeating pseudorandom sequence, not a true hardware random number.

The pseudorandom sequence generated by POKEY isn’t sync’d to the CPU chip, so you will get some randomness out of it.

---

<div class="post-metadata">

### Author: ![beowulff](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/beowulff/32/542_2.png) [@beowulff](https://boards.straightdope.com/u/beowulff)
#### Post date: [December 21, 2015, 10:22pm UTC](https://boards.straightdope.com/t/how-was-randomness-achieved-in-older-video-games/741023/14 "2015-12-21T22:22:10Z")

</div>

> [@KarlGauss](#):
>
> I’m not sure I follow. Do you mean that there wouldn’t have been sufficient time to generate the next random number?

No, what he means is that the digitizer (or synthesizer) isn’t very accurate.  
So, if you have an analog signal that varies continuously over a range of zero - 1 volts, but you only have an 8-bit Analog to Digital converter, you can never end up with better than 256 values (although, if you take extra time you can oversample and get additional precision).

---

<div class="post-metadata">

### Author: ![Jragon](https://avatars.discourse-cdn.com/v4/letter/j/e19b73/32.png) [@Jragon](https://boards.straightdope.com/u/Jragon)
#### Post date: [December 21, 2015, 10:22pm UTC](https://boards.straightdope.com/t/how-was-randomness-achieved-in-older-video-games/741023/15 "2015-12-21T22:22:26Z")

</div>

> [@KarlGauss](#):
>
> I’m not sure I follow. Do you mean that there wouldn’t have been sufficient time to generate the next random number?

Since the randomness is just a measurement of noise, it’s plausible that not enough samples have occurred between readings.

This is a known problem with /dev/random in Unix, which is why you usually use /dev/urandom in time-sensitive or real-time applications (/dev/urandom reads from dev random, and, if there’s no info, will seed a PRNG with the last reading from /dev/random and return that).

It’s like if I was getting my randomness from you flipping coins. You can only flip so quickly, so if I need a bunch of numbers, it’s possible you haven’t flipped enough coins yet and I need to wait for you.

I don’t know if this is a problem with Atari’s implementation, which may sample on-demand, but in /dev/random, it basically just measures noise from a ton of sources and stores them in a file which can be depleted if sampled from too frequently.

---

<div class="post-metadata">

### Author: ![KarlGauss](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/karlgauss/32/3713_2.png) [@KarlGauss](https://boards.straightdope.com/u/KarlGauss)
#### Post date: [December 21, 2015, 10:27pm UTC](https://boards.straightdope.com/t/how-was-randomness-achieved-in-older-video-games/741023/16 "2015-12-21T22:27:12Z")

</div>

Gotcha! (both) Thanks.

---

<div class="post-metadata">

### Author: ![snfaulkner](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/snfaulkner/32/433_2.png) [@snfaulkner](https://boards.straightdope.com/u/snfaulkner)
#### Post date: [December 21, 2015, 10:28pm UTC](https://boards.straightdope.com/t/how-was-randomness-achieved-in-older-video-games/741023/17 "2015-12-21T22:28:26Z")

</div>

My dad would bring home from work every weekend the very first Compaq suitcase-sized “portable” computer (twin 5.25" drives, baby! and either green or amber 10" monochrome display). And some of the games would ask for a seed# on startup. I don’t remember the names of the games at all, however.

---

<div class="post-metadata">

### Author: ![The\_Hamster\_King](https://avatars.discourse-cdn.com/v4/letter/t/8edcca/32.png) [@The\_Hamster\_King](https://boards.straightdope.com/u/The_Hamster_King)
#### Post date: [December 21, 2015, 10:33pm UTC](https://boards.straightdope.com/t/how-was-randomness-achieved-in-older-video-games/741023/18 "2015-12-21T22:33:13Z")

</div>

> [@engineer\_comp\_geek](#):
>
> I was rather surprised to find out that internally, POKEY used a linear feedback shift register to generate a pseudorandom sequence. So someone was lying. It wasn’t actually measuring random noise. It takes a long time for POKEY’s sequence to repeat, but it’s just a repeating pseudorandom sequence, not a true hardware random number.

I just came to the same realization after a bit of digging. POKEY has a hardware implementation of a pseudorandom bit-shifting algorithm.

---

<div class="post-metadata">

### Author: ![Jragon](https://avatars.discourse-cdn.com/v4/letter/j/e19b73/32.png) [@Jragon](https://boards.straightdope.com/u/Jragon)
#### Post date: [December 21, 2015, 10:35pm UTC](https://boards.straightdope.com/t/how-was-randomness-achieved-in-older-video-games/741023/19 "2015-12-21T22:35:42Z")

</div>

Where does POKEY get its seed?

---

<div class="post-metadata">

### Author: ![griffin1977](https://avatars.discourse-cdn.com/v4/letter/g/977dab/32.png) [@griffin1977](https://boards.straightdope.com/u/griffin1977)
#### Post date: [December 21, 2015, 10:41pm UTC](https://boards.straightdope.com/t/how-was-randomness-achieved-in-older-video-games/741023/20 "2015-12-21T22:41:35Z")

</div>

Article on the matter [here](http://www.retrobits.com/2014/07/well-thats-random.html):

> [@](#):
>
> For each of the platforms I’m using for my Retrochallenge entry (Atari 800, Epson PX-8, PDP-11/23+), I wanted to find a suitably fast-changing clock or register that could be used as a seed.  
> .  
> .  
> The PX-8 was the most ideal. There is a 614.4 KHz clock that updates a rolling 16-bit register, the value of which can be read with from the BASIC “INP” function. This function reads values from Z80 I/O registers. Since 614.4 KHz will update the value more than 600,000 times per second, it is unlikely in the extreme that a user could predict when to press a key even if they wanted to.

[Next page](https://boards.straightdope.com/t/how-was-randomness-achieved-in-older-video-games/741023.md?page=2)
