# Little Problem with the random function

**URL:** <https://discourse.processing.org/t/little-problem-with-the-random-function/8155>\
**Category:** Coding Questions\
**Created:** [February 6, 2019, 2:45pm UTC](https://discourse.processing.org/t/little-problem-with-the-random-function/8155 "2019-02-06T14:45:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Voltflo](https://avatars.discourse-cdn.com/v4/letter/v/c0e974/32.png) [@Voltflo](https://discourse.processing.org/u/Voltflo)\
**Post date:** [February 6, 2019, 2:45pm UTC](https://discourse.processing.org/t/little-problem-with-the-random-function/8155/1 "2019-02-06T14:45:22Z")

</div>

So for the Start I just wanted to programme a little game. So in the game you have to catch balls with a bucket. So I just wanted to randomize were the balls are dropping but instead of choosing 1 location he chooses 100 locations while the ball is slowly moving down.

```auto
var Ball = 0
var Bomb = 0
var f1
var f2
var f3
var f4
var f5

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

function draw() {
	background(19, 255, 255);
	//var k=randomSeed(width);
	var f1 = random(width);
	var f2 = random(width);
	var f3 = random(width);
	var f4 = random(width);
	var f5 = random(width);

	rectMode(CENTER);
	rect(mouseX, 650, 100, 100);

	noStroke();
	fill(255, 10, 0);
	ellipse(f1, Ball, 20, 20);
	ellipse(f2, Ball, 20, 20);
	ellipse(f3, Ball, 20, 20);
	ellipse(f4, Ball, 20, 20);
	ellipse(f5, Ball, 20, 20);

	Ball = Ball + 4
}

```

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [February 6, 2019, 3:03pm UTC](https://discourse.processing.org/t/little-problem-with-the-random-function/8155/2 "2019-02-06T15:03:17Z")

</div>

> [@Voltflo](#):
>
> var f1 = random(width);  
> var f2 = random(width);  
> var f3 = random(width);  
> var f4 = random(width);  
> var f5 = random(width);

try to move that up to the setup function?  
but without new declaration!

```auto
f1 = random(width);
f2 = random(width);
f3 = random(width);
f4 = random(width);
f5 = random(width);

```

---

<div class="post-metadata">

**Author:** ![Voltflo](https://avatars.discourse-cdn.com/v4/letter/v/c0e974/32.png) [@Voltflo](https://discourse.processing.org/u/Voltflo)\
**Post date:** [February 6, 2019, 3:09pm UTC](https://discourse.processing.org/t/little-problem-with-the-random-function/8155/3 "2019-02-06T15:09:47Z")

</div>

Thanks. It worked  
I tried that for hours
