# Re Randomizing Variables

**URL:** <https://discourse.processing.org/t/re-randomizing-variables/4745>\
**Category:** Coding Questions\
**Created:** [October 22, 2018, 12:12pm UTC](https://discourse.processing.org/t/re-randomizing-variables/4745 "2018-10-22T12:12:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![klarj](https://avatars.discourse-cdn.com/v4/letter/k/b77776/32.png) [@klarj](https://discourse.processing.org/u/klarj)\
**Post date:** [October 22, 2018, 12:12pm UTC](https://discourse.processing.org/t/re-randomizing-variables/4745/1 "2018-10-22T12:12:10Z")

</div>

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.

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

void setup() {
  background(255);
  size (800, 600);
  t = new target();
  t.newtarget();
  cursor(CROSS);
}

void draw() {
}

void mousePressed() {
  if (dist(mouseX, mouseY, ix, iy) < 50) {
    background(255);
    println("success");
    p = p + 1;
    println(p);
    t.newtarget();
  }
} 

//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

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [October 22, 2018, 12:58pm UTC](https://discourse.processing.org/t/re-randomizing-variables/4745/2 "2018-10-22T12:58:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![klarj](https://avatars.discourse-cdn.com/v4/letter/k/b77776/32.png) [@klarj](https://discourse.processing.org/u/klarj)\
**Post date:** [October 23, 2018, 11:47am UTC](https://discourse.processing.org/t/re-randomizing-variables/4745/3 "2018-10-23T11:47:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [October 23, 2018, 2:07pm UTC](https://discourse.processing.org/t/re-randomizing-variables/4745/4 "2018-10-23T14:07:07Z")

</div>

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