Learn About Random Number Generation on the Amiga Using AMOS BASIC (15-30 mins)

Task: Learn About Random Number Generation

Needed: Amiga Computer or Emulator and Amos BASIC

Time: 15-30 Minutes

Introduction

Like all platforms of the time, AMOS BASIC for the Amiga uses a pseudo random number generator to generate the random numbers used in games and other software. While not completely random, the sequences of numbers are good enough to appear random in gameplay. The key is to provide a random seed such that the sequence of numbers is unlikely to be the same each time called. This was often done using an internal clock or the position of the electron beam as it raced across the CRT screen. The goal of this project is to try calling random numbers in AMOS BASIC and visualizing the output by drawing circles at random X and Y positions and with random colors.

Instructions

The first thing you need is AMOS Professional BASIC. You can download the ADF floppy disk images to load on a Gotek on real hardware, for example. A much easier solution is to download and install the Amiga Game Selector (AGS) that includes AMOS in its Work directory. Press ESC from AGS to get to Workbench and then open Work and look for Programming. This is what I did.

Below is the AMOS edit window with the code to enter. Once entered press the red arrow in the top middle of the screen to run. Hit CTRL-C to end.

The first line of code opens the screen. The next two lines clear the screen with Paper 0 setting the background color to black. The fourth line sets the random seed. Here we set the seed using a timer that gets started when the Amiga is turned on. There is then a DO-LOOP that draws circles at random X and Y coordinates with random colors. Paint fills in the circles with solid color. The Wait VBL (vertical blank) command is just good practice to make sure the screen is done drawing before AMOS gets on to other tasks. Below is what this looks like after running for about 30 seconds.

Comments

This simple demo demonstrates that the random numbers do indeed look pretty random.

Here is the description of random number generation in the AMOS manual.

I had trouble identifying the exact pseudo random number generator that AMOS uses. However, it very likely used a Linear Congruential Generator (LCG) that was common during that time.