# Problem with random

**URL:** https://discourse.processing.org/t/problem-with-random/1541
**Category:** Coding Questions
**Created:** [July 6, 2018, 8:01am UTC](https://discourse.processing.org/t/problem-with-random/1541 "2018-07-06T08:01:25Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![vajo](https://avatars.discourse-cdn.com/v4/letter/v/87869e/32.png) [@vajo](https://discourse.processing.org/u/vajo)
#### Post date: [July 6, 2018, 8:01am UTC](https://discourse.processing.org/t/problem-with-random/1541/1 "2018-07-06T08:01:25Z")

</div>

Hey i want to create a Game in Processing and i need a random command wich Pics a random Numbers of 1 to 5 …  
If i use the normal random Code then IT could happened that a number bigger than 5 …  
I need a special command please send me the command thanks

---

<div class="post-metadata">

### Author: ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)
#### Post date: [July 6, 2018, 9:12am UTC](https://discourse.processing.org/t/problem-with-random/1541/2 "2018-07-06T09:12:50Z")

</div>

```auto
(int) random(1,6);

```

should do it. ~~Although there used to be a bug in Processing that you’d occasionally get 6 there, due to use of `float` over `double`. This might now be fixed.~~

---

<div class="post-metadata">

### Author: ![MxFxM](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@MxFxM](https://discourse.processing.org/u/MxFxM)
#### Post date: [July 6, 2018, 9:24am UTC](https://discourse.processing.org/t/problem-with-random/1541/3 "2018-07-06T09:24:03Z")

</div>

Now that I see that with 6, might this work:

```auto
floor(random(1, 5.99));

```

?  
Just wondering…

---

<div class="post-metadata">

### Author: ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)
#### Post date: [July 6, 2018, 9:34am UTC](https://discourse.processing.org/t/problem-with-random/1541/4 "2018-07-06T09:34:16Z")

</div>

The conversion to `int` will already floor it. Looks like the bug I mentioned was fixed some time ago anyway - [https://github.com/processing/processing/blob/master/core/src/processing/core/PApplet.java#L5110](https://github.com/processing/processing/blob/master/core/src/processing/core/PApplet.java#L5110)
