# How to rewrite function without instancing random()

**URL:** https://discourse.processing.org/t/how-to-rewrite-function-without-instancing-random/23840
**Category:** Coding Questions
**Created:** [September 13, 2020, 4:16pm UTC](https://discourse.processing.org/t/how-to-rewrite-function-without-instancing-random/23840 "2020-09-13T16:16:20Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![bakursky](https://avatars.discourse-cdn.com/v4/letter/b/97f17d/32.png) [@bakursky](https://discourse.processing.org/u/bakursky)
#### Post date: [September 13, 2020, 4:16pm UTC](https://discourse.processing.org/t/how-to-rewrite-function-without-instancing-random/23840/1 "2020-09-13T16:16:20Z")

</div>

I have the eye() function and I want to duplicate it several times that every eye look in a different direction (now random number copy to all function instances)

```auto
  let x=0;
  let y=0;

function setup() {
  createCanvas(500, 500);
}

function draw() {
  background(0);
  translate(250,250);
  eye();
}

function eye(){
  noStroke();
  fill(255);
  circle(0,0,80);
  
  fill(0);
  circle(x,y,40);
  
   if(frameCount > 30) {
    x = random(30)*cos( random(360) );
    y = random(30)*sin( random(360) );
    frameCount=0;
  }
}

```

---

<div class="post-metadata">

### Author: ![leo.nerd](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/leo.nerd/32/6101_2.png) [@leo.nerd](https://discourse.processing.org/u/leo.nerd)
#### Post date: [September 14, 2020, 2:29am UTC](https://discourse.processing.org/t/how-to-rewrite-function-without-instancing-random/23840/2 "2020-09-14T02:29:50Z")

</div>

Try changing the seed to a random number every time your function is called: [https://p5js.org/reference/#/p5/randomSeed](https://p5js.org/reference/#/p5/randomSeed)

And another unrelated comment would be to use `if(frameCount % 30 == 0)` so you wouldn’t have to force `frameCount = 0` (although I’m not sure if it really hurts)

---

<div class="post-metadata">

### Author: ![bakursky](https://avatars.discourse-cdn.com/v4/letter/b/97f17d/32.png) [@bakursky](https://discourse.processing.org/u/bakursky)
#### Post date: [September 16, 2020, 8:34am UTC](https://discourse.processing.org/t/how-to-rewrite-function-without-instancing-random/23840/3 "2020-09-16T08:34:36Z")

</div>

Many thanks, but… any example of implementation, please 😯

---

<div class="post-metadata">

### Author: ![Hyperion65](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hyperion65/32/10569_2.png) [@Hyperion65](https://discourse.processing.org/u/Hyperion65)
#### Post date: [September 18, 2020, 9:49am UTC](https://discourse.processing.org/t/how-to-rewrite-function-without-instancing-random/23840/4 "2020-09-18T09:49:43Z")

</div>

that would be the exact description of using a class instead of a function…
