# Scope and random number generators

**URL:** <https://discourse.processing.org/t/scope-and-random-number-generators/42385>\
**Category:** Beginners\
**Created:** [July 9, 2023, 6:05pm UTC](https://discourse.processing.org/t/scope-and-random-number-generators/42385 "2023-07-09T18:05:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sambo](https://avatars.discourse-cdn.com/v4/letter/s/ed655f/32.png) [@Sambo](https://discourse.processing.org/u/Sambo)\
**Post date:** [July 9, 2023, 6:05pm UTC](https://discourse.processing.org/t/scope-and-random-number-generators/42385/1 "2023-07-09T18:05:49Z")

</div>

I understand the problem with choosing randoms either 1: inside function draw(), or 2: inside functions that are called inside draw, but why is it that random() is a scope error outside of setup() ?  
Is it necessary to generate all randoms in setup(), then save them in arrays for later use, or is there a better option? signed, NewToThisServer

---

<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:** [July 9, 2023, 6:41pm UTC](https://discourse.processing.org/t/scope-and-random-number-generators/42385/2 "2023-07-09T18:41:26Z")

</div>

> [@Sambo](#):
>
> , or is there a better option?

We can prematurely instantiate p5 via `new p5;` so we can access its API right way:

> **[Sierpinski Pentagon \[p5.js\] - GoToLoop - OpenProcessing](https://openprocessing.org/sketch/955445)**
