# Use random() in static method

**URL:** <https://discourse.processing.org/t/use-random-in-static-method/21358>\
**Category:** Beginners\
**Created:** [May 28, 2020, 2:19am UTC](https://discourse.processing.org/t/use-random-in-static-method/21358 "2020-05-28T02:19:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![FallingSloth](https://avatars.discourse-cdn.com/v4/letter/f/ecccb3/32.png) [@FallingSloth](https://discourse.processing.org/u/FallingSloth)\
**Post date:** [May 28, 2020, 2:19am UTC](https://discourse.processing.org/t/use-random-in-static-method/21358/1 "2020-05-28T02:19:58Z")

</div>

I have a static method where I would like to use the random function, however, I get the error

> Cannot make a static reference to the non-static method random(float) from the type PApplet

I’ve tried to google for the error but kept finding stuff that was related to calling your own methods, rather than the built-in methods.

How can I get random numbers in processing from a static method?

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [May 28, 2020, 3:06am UTC](https://discourse.processing.org/t/use-random-in-static-method/21358/2 "2020-05-28T03:06:19Z")

</div>

> [@FallingSloth](#):
>
> How can I get random numbers in processing from a `static` method?

You can directly call Java’s own **random()**:  
[Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Math.html#random()](http://Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Math.html#random())

Or you can create `static` wrapper functions which forward call PApplet’s methods:  
[Processing.GitHub.io/processing-javadocs/core/processing/core/PApplet.html#random-float-float-](http://Processing.GitHub.io/processing-javadocs/core/processing/core/PApplet.html#random-float-float-)

```auto
static final float random(final PApplet p, final float high) {
  return p.random(high);
}

static final float random(final PApplet p, final float low, final float high) {
  return p.random(low, high);
}

```

But as you can see above, we have to pass the sketch’s PApplet reference for such wrapper approach.
