# Random Number From Variables

**URL:** <https://community.thunkable.com/t/random-number-from-variables/42256>\
**Category:** Questions about Thunkable X\
**Created:** [August 20, 2018, 1:17pm UTC](https://community.thunkable.com/t/random-number-from-variables/42256 "2018-08-20T13:17:33Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![MersauX](https://avatars.discourse-cdn.com/v4/letter/m/439d5e/32.png) [@MersauX](https://community.thunkable.com/u/MersauX)\
**Post date:** [August 20, 2018, 1:17pm UTC](https://community.thunkable.com/t/random-number-from-variables/42256/1 "2018-08-20T13:17:33Z")

</div>

Hi, I’m trying to make my first app, a random number picker from a range between two numbers you set on the first page. On the second page I have the following formula. Adding etc works, but random number always returns some number outside of the range. Please help. 🙂

 ![03](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/7/f/7fe93d8aab4b555c7acddfdf27e82159b39e7eff.png)

---

<div class="post-metadata">

**Author:** ![actech](https://avatars.discourse-cdn.com/v4/letter/a/3d9bf3/32.png) [@actech](https://community.thunkable.com/u/actech)\
**Post date:** [August 20, 2018, 1:34pm UTC](https://community.thunkable.com/t/random-number-from-variables/42256/2 "2018-08-20T13:34:45Z")

</div>

Hi,

what value is contained in NFrom, NTo and what is returned as a random number?

---

<div class="post-metadata">

**Author:** ![MersauX](https://avatars.discourse-cdn.com/v4/letter/m/439d5e/32.png) [@MersauX](https://community.thunkable.com/u/MersauX)\
**Post date:** [August 20, 2018, 4:39pm UTC](https://community.thunkable.com/t/random-number-from-variables/42256/3 "2018-08-20T16:39:48Z")

</div>

I’m setting the numbers using input fields and saving them to local storage. I’m not sure if there is an option to save items as integers I’m totally new to this. The random number returns some really random number but not within the range set, for example I set 2 and 5 as the range and it gives me 13, or -43 and similar.

![13](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/8/a/8ad8a298738a1ac6318b3afffcd87c6d06f4fd21.png)

---

<div class="post-metadata">

**Author:** ![AcrobatEpee](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/acrobatepee/32/26336_2.png) [@AcrobatEpee](https://community.thunkable.com/u/AcrobatEpee)\
**Post date:** [August 20, 2018, 5:32pm UTC](https://community.thunkable.com/t/random-number-from-variables/42256/4 "2018-08-20T17:32:25Z")

</div>

Are you sure that NFrom is the lowest number and NTo the highest ?  
Next if it is try puttin the local storage under the other one and not inside and put the label text outside of both but inside screen opens.  
Hope it helps.

---

<div class="post-metadata">

**Author:** ![khunter83](https://avatars.discourse-cdn.com/v4/letter/k/b3f665/32.png) [@khunter83](https://community.thunkable.com/u/khunter83)\
**Post date:** [August 20, 2018, 8:54pm UTC](https://community.thunkable.com/t/random-number-from-variables/42256/5 "2018-08-20T20:54:33Z")

</div>

Funnily enough I am also creating a random number generator and I am also having this problem!

These are my blocks.  
My text inputs start with 0 and 100 and if I don’t edit them - they work perfectly.  
If I change them, it randomly works, randomly goes wrong

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/b/8/b8eed0f0353d10f59352696fa373f11d442244ba.png)

I also tried it the following way with variables:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/2/0/2058dbaff64dc8c968d0aa43e07fd3d86a3d3980.png)

I got the exact same results

Edit: I also added in an error message if my 2nd number is smaller than my first number.  
If I change the first number to 5 and the 2nd to 1000, this error appears 😥

---

<div class="post-metadata">

**Author:** ![khunter83](https://avatars.discourse-cdn.com/v4/letter/k/b3f665/32.png) [@khunter83](https://community.thunkable.com/u/khunter83)\
**Post date:** [August 20, 2018, 9:07pm UTC](https://community.thunkable.com/t/random-number-from-variables/42256/6 "2018-08-20T21:07:41Z")

</div>

I _think_ I have it fixed.

Use the Round function to round your inputs before getting a random value and it seems to work.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/2/4/24cdade2b81965c4201ec600c37d77ee3c622719.png)

---

<div class="post-metadata">

**Author:** ![MersauX](https://avatars.discourse-cdn.com/v4/letter/m/439d5e/32.png) [@MersauX](https://community.thunkable.com/u/MersauX)\
**Post date:** [August 20, 2018, 9:36pm UTC](https://community.thunkable.com/t/random-number-from-variables/42256/7 "2018-08-20T21:36:46Z")

</div>

Thank you! This seems to have worked! I would have never figured it out! 😄🍺

---

<div class="post-metadata">

**Author:** ![ioannis](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/ioannis/32/146956_2.png) [@ioannis](https://community.thunkable.com/u/ioannis)\
**Post date:** [November 8, 2024, 12:00pm UTC](https://community.thunkable.com/t/random-number-from-variables/42256/8 "2024-11-08T12:00:40Z")

</div>


