# Random number

**URL:** <https://community.homey.app/t/random-number/18502>\
**Category:** Questions & Help\
**Created:** [September 25, 2019, 3:59pm UTC](https://community.homey.app/t/random-number/18502 "2019-09-25T15:59:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marcel\_Ubels](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/marcel_ubels/32/18860_2.png) [@Marcel\_Ubels](https://community.homey.app/u/Marcel_Ubels)\
**Post date:** [September 25, 2019, 3:59pm UTC](https://community.homey.app/t/random-number/18502/1 "2019-09-25T15:59:20Z")

</div>

Is there a way to get a number between 0-9 random into a variable?

And if that is possible the next time the flow operates the first random number achieved will not be used the next time?

Want to use this to listen to radiostations on my Sonos, but want to listen to five different stations in a week. It would be nice if the way the radiostation are selected happens in a random way.

---

<div class="post-metadata">

**Author:** ![Caseda](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/caseda/32/138695_2.png) [@Caseda](https://community.homey.app/u/Caseda)\
**Post date:** [September 25, 2019, 5:27pm UTC](https://community.homey.app/t/random-number/18502/2 "2019-09-25T17:27:44Z")

</div>

It is even really easy when using the normal logic  
`{{random(0,9)}}`  
This will choose a random number between 0 and 9 everytime it is being run

---

<div class="post-metadata">

**Author:** ![Marcel\_Ubels](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/marcel_ubels/32/18860_2.png) [@Marcel\_Ubels](https://community.homey.app/u/Marcel_Ubels)\
**Post date:** [September 25, 2019, 5:33pm UTC](https://community.homey.app/t/random-number/18502/3 "2019-09-25T17:33:45Z")

</div>

Wow, that easy? Thx, gives even more possibilities.

---

<div class="post-metadata">

**Author:** ![Torbjorn\_Melbye](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/torbjorn_melbye/32/18194_2.png) [@Torbjorn\_Melbye](https://community.homey.app/u/Torbjorn_Melbye)\
**Post date:** [October 11, 2020, 11:55am UTC](https://community.homey.app/t/random-number/18502/4 "2020-10-11T11:55:02Z")

</div>

Hi Caseda.  
I see that this is a while back, but I’m trying to make this work.  
I am using Google TTS and I want to make Google give a number at random between 1 and 6 like a die.

When I try your way it results in an unspeakably high number. Any idea why this would happen?

Thanks.

---

<div class="post-metadata">

**Author:** ![Caseda](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/caseda/32/138695_2.png) [@Caseda](https://community.homey.app/u/Caseda)\
**Post date:** [October 11, 2020, 12:21pm UTC](https://community.homey.app/t/random-number/18502/5 "2020-10-11T12:21:42Z")

</div>

This is a “bug” of float numbers in Javascript, you can “fix” this by rounding it up `{{round(random(0,6))}}`

---

<div class="post-metadata">

**Author:** ![Torbjorn\_Melbye](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/torbjorn_melbye/32/18194_2.png) [@Torbjorn\_Melbye](https://community.homey.app/u/Torbjorn_Melbye)\
**Post date:** [October 11, 2020, 1:27pm UTC](https://community.homey.app/t/random-number/18502/6 "2020-10-11T13:27:44Z")

</div>

Thank you. Figured it out and works great now 👍🏻  
Is it a bug? Seems the round property just removes the decimals.

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [October 11, 2020, 1:30pm UTC](https://community.homey.app/t/random-number/18502/7 "2020-10-11T13:30:11Z")

</div>

> [@Torbjorn\_Melbye](#):
>
> Is it a bug?

No.
