The first random value is always the same when using randomSeed

Correlation of the first numbers is a well-documented aspect of the Java PRNG. For more, read:

(Aside: This correlation also happens in p5.js.)

If you want a pseudo-random number, don’t set the random seed each frame – and especially don’t set the seed with 1, 2, 3, 4, 5, et cetera, because contiguous first values are highly correlated. Instead, either:

  1. set the seed once in setup randomSeed(0) and then call random() in draw as often as you want with no correlation, or
  2. if you must set a different seed each frame (which is a bad idea), at least do it from non-contiguous numbers, for example multiplying the frameCount by a large prime number: randomSeed(frameCount*1777)

( or don’t set the seed at all!)

3 Likes