Re Randomizing Variables

I’m trying to create a program where 1st a ball is randomly placed and when clicked on, the old one is removed and a new one is placed randomly. The problem is that even though I do random() again for that variable it doesn’t refresh the number used and it just stays the same.

target t;
float fx;
float fy;
int ix = int(fx);
int iy = int(fy);
int p = 0;

void setup() {
  size (800, 600);
  t = new target();

void draw() {

void mousePressed() {
  if (dist(mouseX, mouseY, ix, iy) < 50) {
    p = p + 1;

//target class

class target {

  void newtarget() {
    fx = random(780);
    fy = random(580);
    fill(0, 255, 0);
    ellipse(ix, iy, 50, 50);

Any help is wanted

1 Like

You are using ix and iy for the Position of your ellipse, But you are randomizing fx. The ix = (int) fx; is only executed at the Start of your Sketch once.

1 Like

Thank you so much, not sure how I missed that.

No problem :wink: . Try to keep your Names as distinct as possibile, to avoid such confusions^^