Hello. Recently, I’ve been working on a sketch in which I need to line up circles in a random order. Basically, I have an array with all the x-coordinates of the circles, and I have a for loop in setup to display enough circles. The problem is that if I say this:
function setup() {
var xArray = [100, 225, 350, 475, 500]
for (i = 0; i < xArray.length; i++) {
fill(50*i)
circle(xArray[floor(random(0, xArray.length))], 200, 50)
}
}
…then the random() function can and does repeat itself — instead of getting my circles in a line with a random shade of gray, they’re frequently on top of each other. I don’t know of a “random() except” function, and I’m guessing it doesn’t exist in such a simple form. I’d very much appreciate it if anyone more skilled than me could show me a workaround or some other solution.
Thanks!