### Spirograph Random Numbers: What Are The Odds?

Posted by Ed in Machine Shop, Science, Software on 2017-12-27

The GCMC Spirograph Generator program chooses parameters using pseudo-random numbers based on a seed fed in from the Bash script, so I was surprised to see two plots overlap *exactly*:

The two overlapping traces are the 15 inward-pointing wedges around the central rosette.

The first one:

(PRNG seed: 38140045) (Paper size: [16.50in,14in]) (PlotSize: [15.50in,13.00in]) (Stator 3: 150) (Rotor 4: 40) (GCD: 10) (Offset: -0.94) (Dia ratio: -0.27) (Lobes: 15) (Turns: 4) (Plot scale: [5.11in,4.29in]) (Tool change: 1) T1 M6

The second one:

(PRNG seed: 74359295) (Paper size: [16.50in,14in]) (PlotSize: [15.50in,13.00in]) (Stator 3: 150) (Rotor 4: 40) (GCD: 10) (Offset: -0.93) (Dia ratio: -0.27) (Lobes: 15) (Turns: 4) (Plot scale: [5.12in,4.30in]) (Tool change: 3) T3 M6

The Offset isn’t quite the same, but the pen width covers up the difference.

With only four Stators and 17 Rotors, the probability of picking the same pair works out to 0.25 × 0.059 = 1.4%. You can sometimes get the same number of Lobes and Turns from several different Stator + Rotor combinations, but these were exact matchs with the same indices.

The Pen Offset within the Rotor comes from a fraction computed with ten bit resolution, so each Offset value represents slightly under 0.1% of the choices. If any four adjacent values look about the same, then it’s only eight bits of resolution and each represents 0.4%.

The Rotor and Stator set the Diameter ratio, but the sign comes from what’s basically a coin flip based on the sign of a fraction drawn from 256 possibilities; call it 50%.

Overall, you’re looking at a probability of 28 ppm = 0.0028%, so I (*uh*, probably) won’t see another overlay for a while …

I don’t know how to factor the PRNG sequence into those numbers, although it surely affects the probability. In this case, two different seeds produced nearly the same sequence of output values, within the resolution of my hack-job calculations.

Whatever. It’s good enough for my simple purposes!

## Blowback