Random values in Draw?

Hi, I have a grid of circles iterated on the x and y axis. I want to assign individual random sizes to them but because of the draw function the random numbers change every frame and animate the size rather than assigning a static value to each object. Suggestions? Thank you!

Hi Superflea… one way to approach this would be to create a table in the setup() function with a random size for each ellipse and then iterate through this table in your draw routine (using ipairs) to assign the random size to each ellipse…


Another solution would be to set the random seed at the start of the draw() call. This ensures that exactly the same sequence of numbers is generated each time:

function draw()
    background( 0 )

    math.randomseed( 1234 )

    ellipse( 100, 100, math.random( 10, 100 ) )

    ellipse( 200, 200, math.random( 10, 100 ) )

    ellipse( 300, 300, math.random( 10, 100 ) )

Edit: I think @Blanchot’s solution is better. This is just an alternative.

Thank you for the replies, I’ll give it a try and let you know!

Worked like a charm, thanks!

For the record, I used Simeon’s method, but added a random in the setup() to provide the seed for the randomseed, so that each time I run the program the outcome is different.

Must say that Codea is proving hugely instructive and fun!