Maximum number in randomSeed() p5js

Hello! What is maximum number that can be used in randomSeed() in P5JS?

Hi @Nik,

The value is a 32bit unsigned integer, so …

An unsigned integer is a 32-bit datum that encodes a nonnegative integer in the range [0 to 4294967295]

Cheers
— mnse

remark: you can also put other values regarding the js Number specification, but interally it will be casted to unsigned 32bit integer :slight_smile:

2 Likes

The seed is stored by this “private” method below:

Its comment states that >>> 0 truncates the result to an unsigned 32-bit (4-byte) integer range, which is from 0 to 2**32 - 1 or 4_294_967_295 max.

You can read about the unsigned right shift operator on this link below:

Here’s a shorter way to write this[stateProperty] = (val == null ? Math.random() * m : val) >>> 0; using the nullish coalescing operator ??:

this[stateProperty] = (val ?? Math.random() * m) >>> 0;
2 Likes

GoToLoop many thanks!

1 Like