The Gameduino hardware has a built-in random number generator. The hardware uses it internally for the white noise sound effect, and your code can access it using the coprocessor's RANDOM register.
Here it is being used to fill the screen with random noise - in the style of an off-station analog television.
#include <SPI.h>
#include <GD.h>
#include "random.h"
void setup()
{
GD.begin();
int i;
for (i = 0; i < 256; i++) {
GD.wr16(RAM_PAL + (4 * i + 0) * 2, RGB(0,0,0));
GD.wr16(RAM_PAL + (4 * i + 1) * 2, RGB(0x20,0x20,0x20));
GD.wr16(RAM_PAL + (4 * i + 2) * 2, RGB(0x40,0x40,0x40));
GD.wr16(RAM_PAL + (4 * i + 3) * 2, RGB(0xff,0xff,0xff));
}
GD.microcode(random_code, sizeof(random_code));
}
void loop()
{
}
After the microprogram is loaded, there is nothing else that the Arduino program needs to do; the Gameduino continuously updates the background character display.
start-microcode random
\ Fill PICTURE and CHARACTER RAM with random numbers
: main
d# 0
begin
RANDOM c@ over c!
1-
h# 1FFF and
again
;
end-microcode