Generate one random number

how can I generate only one random number per 200 frameCount? my code does produce many random numbers per 200 frameCount but I want it to repeat only once.

you mean like?

void setup() {}
void draw() {
 if ( frameCount%200 == 0 ) println( random(1) ); 
}

Given this is the p5js forum category…:

function draw() {
  frameCount % 200 || print(random());
}
1 Like

It produces two numbers

I want to assign it to my circle diameter, it prints one number but my diameter changes quickly as it seem producing too many of them!

"use strict";

const FRAMES = 200, MAX_DIAM = 50, BG = 0o350;
let diam = MAX_DIAM >> 1;

function draw() {
  frameCount % FRAMES || (diam = random(MAX_DIAM));
  background(BG).circle(width >> 1, height >> 1, diam);
}
1 Like