# Random Numbers Generator

**URL:** https://discourse.processing.org/t/random-numbers-generator/5563
**Category:** Coding Questions
**Created:** [November 15, 2018, 2:19pm UTC](https://discourse.processing.org/t/random-numbers-generator/5563 "2018-11-15T14:19:18Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![SpeedKillerX](https://avatars.discourse-cdn.com/v4/letter/s/278dde/32.png) [@SpeedKillerX](https://discourse.processing.org/u/SpeedKillerX)
#### Post date: [November 15, 2018, 2:19pm UTC](https://discourse.processing.org/t/random-numbers-generator/5563/1 "2018-11-15T14:19:18Z")

</div>

I am making a random number generator using the code:

void setup(){  
size(600,600);  
textSize(40);  
}

void draw(){  
background(0);  
text(random(20),100,200);  
frameRate(1);  
}  
But I want the numbers to stop when I click my mouse, and display the number on the screen, but cant quite figure out how to do this.

---

<div class="post-metadata">

### Author: ![matheplica](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/matheplica/32/21035_2.png) [@matheplica](https://discourse.processing.org/u/matheplica)
#### Post date: [November 15, 2018, 4:22pm UTC](https://discourse.processing.org/t/random-numbers-generator/5563/2 "2018-11-15T16:22:43Z")

</div>

Maybe this

```auto
boolean randomize = true;
float value;
void setup() {
  size(600, 600);
  frameRate(1);
  textSize(40);
}
void draw() {
  background(0);
  if (randomize) value = random(20);
  text(value, 100, 200);
}
void mouseClicked() {
  randomize =! randomize;
}

```

---

<div class="post-metadata">

### Author: ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)
#### Post date: [November 15, 2018, 5:07pm UTC](https://discourse.processing.org/t/random-numbers-generator/5563/3 "2018-11-15T17:07:27Z")

</div>

The solution of @matheplica is nice because it allows you to extend on it and do draw other things on screen while still displaying the number.

Now a simpler approach but way less extendable would be to deal with everything in your mouseClicked() function:

```auto
void setup() {
  size(600, 600);
  background(20);
}

void draw() {
}

void mouseClicked() {
  background(20);
  fill(200);  
  textSize(40);
  text(random(20), 100, 200);
}

```

---

<div class="post-metadata">

### Author: ![Eeyorelife](https://avatars.discourse-cdn.com/v4/letter/e/439d5e/32.png) [@Eeyorelife](https://discourse.processing.org/u/Eeyorelife)
#### Post date: [November 15, 2018, 8:31pm UTC](https://discourse.processing.org/t/random-numbers-generator/5563/4 "2018-11-15T20:31:02Z")

</div>

Or prehaps:

```auto
boolean stop = false;
void setup(){
  size(600,600);
  textSize(40);
}

void draw(){
  background(0);
  text(random(20),100,200);
  frameRate(1);
}

void mousePressed(){
  if(!stop){
    noLoop();
    stop = !stop;
  } else {
    loop();
    stop = !stop;
  }
}

```

There are many ways to do it
