xxxxxxxxxx
25
//{!1} An array to keep track of how often random numbers are picked
let randomCounts = [];
function setup() {
createCanvas(640, 240);
for (let i = 0; i < 20; i++) {
randomCounts[i] = 0;
}
}
function draw() {
background(255);
//{!2} Pick a random number and increase the count.
let index = floor(random(randomCounts.length));
randomCounts[index]++;
stroke(0);
fill(175);
let w = width / randomCounts.length;
//{!3 .offset-top} Graphing the results
for (let x = 0; x < randomCounts.length; x++) {
rect(x * w, height - randomCounts[x], w - 1, randomCounts[x]);
}
}