Random Number Generator Graphing Probability


This random number generator Simon built in Processing simultaneously graphs the probability of the values as you “throw the dice”. This is Simon’s own code and what’s more, he has turned it into a truly scientific experiment/observation. Simon programmed the generator to automatically throw the dice every 60 frames a second (i.e. every 1/15th of a second). The graph showing the probability of certain values should increasingly resemble a perfect isoceles triangle the more throws occur, because the probability of you getting 7 is much higher than those of getting 2 or 12.

Random Number Generator Graphing Probability 9 Feb 2018Random Number Generator Graphing Probability 9 Feb 2018 2

The perfect triangle was drawn at around 4000 throws.

Simon also experimented with programming the same generator for 3 dice. The graph should then form a bell shaped curve, a parabola, and takes a longer while to shape up. “As the number of dice grows towards infinity, the distribution will change from a uniform distribution to a Gaussian distribution”, – Simon explains.

Random Number Generator Graphing Probability 9 Feb 2018 with 3 dice towards parabola 1Random Number Generator Graphing Probability 9 Feb 2018 with 3 dice towards parabola 2Random Number Generator Graphing Probability 9 Feb 2018 with 3 dice towards parabola 3Random Number Generator Graphing Probability 9 Feb 2018 with 3 dice towards parabola 4


Live Stream #8: Games on a grid in Processing

Simon’s live stream last night was a blast. Simon worked on two games on a grid: 15s Puzzle and Connect Four, both in Processing (Java). He had already made the 15s Puzzle before, but built the Connect Four (also called Four in a Row) without any prior preparation.

The stream got lots of views as Daniel Shiffman kindly advertised it again on his Twitter:

Let me also archive the live chat here, to save it from oblivion:

Schermafbeelding 2018-02-08 om 22.05.26Schermafbeelding 2018-02-08 om 22.06.34Schermafbeelding 2018-02-08 om 22.07.14Schermafbeelding 2018-02-08 om 22.07.32Schermafbeelding 2018-02-08 om 22.07.52Schermafbeelding 2018-02-08 om 22.08.14

Simon playing his game together with sis:

Patterns. Hilbert Curve in Processing.

This is a project about pattern. “Some people look for patterns. We call those people mathematicians”, Matt Parker said in a Numberphile video. I think I have never heard a description that would suit Simon better. He has always been looking for patterns, everywhere – in music, in toys, in ice-cream menus, in books about space or chemistry manuals. When he was little and spent days ranking planets and stars from memory, we used to think space was his true interest. Or elementary particles. Or the periodic table. Or Japanese letters. Or Greek letters. As it turned out later, he simply picked the topics that had more pattern in them, that were easy to classify. To this day, he enjoys music theory much more than actually playing the piano, and when listening to music I see him move his hand rhythmically every time a recognisable/ repetitive pattern is distinguishable.

In the video below, Simon is trying to build a Hilbert Curve (a space filling curve, a type of fractal) in Processing. The project was inspired by the math videos by 3Blue1Brown and the Koch Snowflake example by Daniel Shiffman (Chapter 8 in his book The Nature of Code, Fractals).

Links to the Hilbert Curve videos on the 3Blue1Brown channel:

Langton’s Ant in p5.js

Simon wrote this JavaScript code for Langton’s Ant (a type of Cellular Automaton) himself, inspired by Daniel Shiffman’s description/version in Processing (Java) during the Coding Train live stream on January 5.

Link to Simon’s sketch: http://alpha.editor.p5js.org/simontiger/sketches/rJeKLICmM

Simon later also made a pixel level version: http://alpha.editor.p5js.org/simontiger/sketches/rJeKLICmM

And a version with multiple ants: http://alpha.editor.p5js.org/simontiger/sketches/r1Ry_FQ4M

(Simon also loves the Numberphile video about how Langton’s Ant works and forms a mysterious “highway” after a certain number of moves).

Simon’s Fibonacci function and Fibonacci counter in p5.js

Simon came up with this Fibonacci function while taking a walk downtown:

Schermafbeelding 2017-12-23 om 02.41.53

f(0) = 0

f(1) = 1

f(n) = f(n-1)+f(n-2)

When we got home, he used the function to build a Fibonacci counter in p5.js:

You can play with Simon’s Fibonacci counter online at: https://alpha.editor.p5js.org/simontiger/sketches/Skhr3o8Gf

The idea about the Fibonacci function struck Simon when he was looking down at the cobbles under his feet. “Look, Mom! It’s a golden rectangle!”, he shouted:


He had read that golden ratio has a direct connection to the Fibonacci sequence. The same evening, he took out his compasses to draw a golden rectangle (this time not his own invention, but following the steps from his Murderous Math book):



If you turn the page, the smaller rectangle is a golden rectangle as well, and if you slice a square off of it, the remaining rectangle will also have the golden proportions. You can continue doing this infinitely. The sizes of the rectangles will exactly correspond to the numbers in the Fibonacci sequence, which makes these drawings an illustration to the sequence.


The next day, Simon showed his function to his math teacher. Below are the Fibonacci sequence numbers he got through his selfmade JavaScript program. After a certain number, the computer started taking too long to compute the following number in the sequence (several seconds per number), but didn’t crash.


Tetris in Processing continued

Inspired by a Meth Meth Method Tetris video, Simon has come back to his Tetris project in Processing, something he started a long while ago and never finished. At the moment, the primary difficulty he experiences is having the pieces accumulate at the bottom of the grid and not vanish immediately once hit by other pieces. Work in progress.

Simon’s Music Random Walker

Link to Simon’s project in progress: https://codepen.io/simontiger/pen/LOg…

The walk begins with a white grid. Every time the walker first visits a cell, it first turns purple and the green number inside the cell increments with every next visit. Simon wants to assign a musical tone to each cell as a next step.


He started working on his own database for the tone frequencies (7 octaves in the 7 x 7 grid), but later lost all his (unsaved) work when his laptop froze. Not sure anymore whether this project will ever get finished 😦 as Simon doesn’t feel like retyping the database again.