How to make a variable random in p5.js

Prior to setup() do this:

let SegmentCount;

That makes the name SegmentCount global. Thereafter, you can assign the variable a value wherever else it is necessary. Inside setup() or draw(), do not begin the assignment statement with let, or you will be declaring a local variable with the same name.

1 Like