Sunday, March 8, 2026

Code Math: Sine as pseudo random number generator

Lets use sine as a randomness provider to generate a infinite sequence of random numbers with no state:

1. Sine wave: 

sin(x)

2. Sample the wave by an non linear expression in order to avoid the linear repeat pattern of the sine: 

sin(x ** 3)

3. Extract only the values at integer points that represent the indexes of the random numbers in the sequence: 

sin(floor(x) ** 3)

4. Map the optional seed to the 0-1 range and added multiplied by 2PI in the sample location: 

sin((floor(x) + seed * 2 * Math.PI) ** 3)

Graph of each:



done_