# Random Number Generator

**URL:** <https://community.glideapps.com/t/random-number-generator/81763>\
**Category:** Ask for Help\
**Created:** [May 7, 2025, 10:08pm UTC](https://community.glideapps.com/t/random-number-generator/81763 "2025-05-07T22:08:27Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kemal1973](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/kemal1973/32/72721_2.png) [@Kemal1973](https://community.glideapps.com/u/Kemal1973)\
**Post date:** [May 7, 2025, 10:08pm UTC](https://community.glideapps.com/t/random-number-generator/81763/1 "2025-05-07T22:08:27Z")

</div>

Hello,  
How to Generate Random Numbers within Range  
for example:input numbers are 1 and 5 then generate 4.365  
It is important that the answer is in decimals, not whole numbers.  
Thanks for helping me

---

<div class="post-metadata">

**Author:** ![HTML](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/html/32/87893_2.png) [@HTML](https://community.glideapps.com/u/HTML)\
**Post date:** [May 7, 2025, 10:27pm UTC](https://community.glideapps.com/t/random-number-generator/81763/2 "2025-05-07T22:27:56Z")

</div>

```auto
function getRandomDecimal(min, max) {
  return min + (max - min) * Math.random();
}

let random = getRandomDecimal(1, 5);
return (random); // Example: 4.365

```

Ps: replace 1 and 5 with p1 and p2 in the JavaScript column.

---

<div class="post-metadata">

**Author:** ![Hassan\_Nadeem](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/hassan_nadeem/32/72956_2.png) [@Hassan\_Nadeem](https://community.glideapps.com/u/Hassan_Nadeem)\
**Post date:** [May 7, 2025, 11:19pm UTC](https://community.glideapps.com/t/random-number-generator/81763/3 "2025-05-07T23:19:01Z")

</div>

Do you want the random number to be repeated on multiple rows or it has to be unique on each row?

---

<div class="post-metadata">

**Author:** ![Nicolas\_Joseph](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/nicolas_joseph/32/76105_2.png) [@Nicolas\_Joseph](https://community.glideapps.com/u/Nicolas_Joseph)\
**Post date:** [May 7, 2025, 11:24pm UTC](https://community.glideapps.com/t/random-number-generator/81763/4 "2025-05-07T23:24:49Z")

</div>

Hello @Kemal1973 🙂

In additon to @HTML’s response, there is also a two steps method using **Computed columns** :

1. Create a `Random Number` (Random Number) column. It will generate a value between 0 and 1 by default, based on a seed. Useful if your pseudorandom number generator must be _deterministic_ (i.e.: if you use the same seed, you’ll get the same result)  

2. Create a `Random Number in range` (Math) with this formula `random * (max - min) + min`. For the explanation, it’s quite logic:

- with `min` = 1 and `max` = 5
- if random provides 0, you have `0 * 4 + 1` = 1
- if random provides 1, you have `1 * 4 + 1` = 5
- anything between 0 and 1 will cover the range inbetween 😉  
  

You will obtain the following table:

 ![Random Number in range](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/2/b/2bfc9a9ee315fbc385ef3df6eb0896c1b9576b38.png)

  

Hope that’s useful 😉

---

<div class="post-metadata">

**Author:** ![nathanaelb](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/nathanaelb/32/43079_2.png) [@nathanaelb](https://community.glideapps.com/u/nathanaelb)\
**Post date:** [May 7, 2025, 11:47pm UTC](https://community.glideapps.com/t/random-number-generator/81763/5 "2025-05-07T23:47:13Z")

</div>

> [@Nicolas\_Joseph](#):
>
> Useful if your pseudorandom number generator must be _deterministic_ (i.e.: if you use the same seed, you’ll get the same result)

I would add to Nicolas’ answer that should the `Seed` of the `Random Number` column be based off a timestamp (like a `Date` column) and in particular one that changes constantly (or every 10 seconds like the `Now` value in a `Math` column) then you can have random numbers that are consistently different and constantly changing every 10 seconds. I am not sure 100% but I believe “consistently” here is correct.

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [May 8, 2025, 4:06am UTC](https://community.glideapps.com/t/random-number-generator/81763/6 "2025-05-08T04:06:06Z")

</div>

That would give you the same value on every row, which may or may not be what is desired.

If instead a different value on every row is desired, I would use a RowID as the seed, and then apply the formula given by @Nicolas_Joseph

 ![CleanShot 2025-05-08 at 12.05.33@2x](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/7/a/7ade38306212cd338d0bd6928a368b50d6a64274.jpeg)

---

<div class="post-metadata">

**Author:** ![nathanaelb](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/nathanaelb/32/43079_2.png) [@nathanaelb](https://community.glideapps.com/u/nathanaelb)\
**Post date:** [May 8, 2025, 9:04am UTC](https://community.glideapps.com/t/random-number-generator/81763/7 "2025-05-08T09:04:19Z")

</div>

I think it really depends on the use case and the UX in the app:

1. If I needed a list of random numbers then I would use Row IDs as the seed as Nicolas suggested.

2. And if I needed one random number only, such as one generated by the click of a button, I would do this in a single row, probably in a user-specific column, and I’d use date-time as a seed to simulate changing row IDs.

---

<div class="post-metadata">

**Author:** ![Kemal1973](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/kemal1973/32/72721_2.png) [@Kemal1973](https://community.glideapps.com/u/Kemal1973)\
**Post date:** [May 8, 2025, 10:21pm UTC](https://community.glideapps.com/t/random-number-generator/81763/8 "2025-05-08T22:21:54Z")

</div>

Thank you for everybody’s response.@nathanaelb and @Nicolas_Joseph .I used this method.

---

<div class="post-metadata">

**Author:** ![Kemal1973](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/kemal1973/32/72721_2.png) [@Kemal1973](https://community.glideapps.com/u/Kemal1973)\
**Post date:** [May 8, 2025, 10:39pm UTC](https://community.glideapps.com/t/random-number-generator/81763/9 "2025-05-08T22:39:29Z")

</div>

Hello,  
I tried this but it didn’t work.I think because of my free plan and JavaScript column doesn’t support.Am i right?

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [May 8, 2025, 11:04pm UTC](https://community.glideapps.com/t/random-number-generator/81763/10 "2025-05-08T23:04:40Z")

</div>

JavaScript is available on all plans. If you show us how you configured the column we may be able to point out where it is wrong.

---

<div class="post-metadata">

**Author:** ![HTML](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/html/32/87893_2.png) [@HTML](https://community.glideapps.com/u/HTML)\
**Post date:** [May 9, 2025, 1:37am UTC](https://community.glideapps.com/t/random-number-generator/81763/11 "2025-05-09T01:37:36Z")

</div>

It will work on any plan, maybe you did not set it up correctly:

 ![Screenshot 2025-05-08 at 9.34.38 PM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/9/3/93a20ebdd3fb46e79b0917d22016d5136e239932.png)  
 ![Screenshot 2025-05-08 at 9.35.08 PM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/d/2/d24ac79c1c8257c0d4f8599acab05a50b9a3e6a1.jpeg)

copy and paste this code:

```auto

function getRandomDecimal(min, max) {
  return min + (max - min) * Math.random();
}

let random = getRandomDecimal(p1, p2);
if(!p1 || !p2) {return 0}
else {
return (random)}

```

---

<div class="post-metadata">

**Author:** ![Kemal1973](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/kemal1973/32/72721_2.png) [@Kemal1973](https://community.glideapps.com/u/Kemal1973)\
**Post date:** [May 9, 2025, 2:14pm UTC](https://community.glideapps.com/t/random-number-generator/81763/12 "2025-05-09T14:14:07Z")

</div>

Thank you @HTML 👍

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/system/32/53398_2.png) [@system](https://community.glideapps.com/u/system)\
**Post date:** [May 16, 2025, 2:14pm UTC](https://community.glideapps.com/t/random-number-generator/81763/13 "2025-05-16T14:14:43Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
