Skip to main content
Solved

Random number functions

  • August 2, 2016
  • 39 replies
  • 1316 views

Forum|alt.badge.img+10

Perhaps I’m missing it, but how do I generate random numbers? I am missing “randbetween” and “rnd” from Excel.
Thanks for any and all help.

Best answer by Mahmoud_Habib

Here’s a way to generate random number using formula field in airtable
first choose a MIN and MAX range for your random numbers then use the following formula:

(VALUE(DATETIME_FORMAT(CREATED_TIME(), ‘0.smh’))*(MAX-MIN))+MIN
this generates the following:

This topic has been closed for replies.

39 replies

Forum|alt.badge.img+5

We don’t have any random number functions at the moment, but I’ll reach out to you once we implement something like this. Can you share why you need a random number function? We might be able to provide a workaround.


Forum|alt.badge.img+10
  • Author
  • Known Participant
  • August 2, 2016

We don’t have any random number functions at the moment, but I’ll reach out to you once we implement something like this. Can you share why you need a random number function? We might be able to provide a workaround.


I use Airtable to generate sample data for prototyping/mocking up a series of applications my company is developing. I often want to have sample data that represents a meaningful distribution across a set of values. In the past I either used Excel or https://www.mockaroo.com/

It’d be great to just use one tool.


  • New Participant
  • October 13, 2016

Am also missing a Random function,

  • which would take a Random Seed.
  • Allow negative to positive range
  • Allow fractions

Looking for a random function something like:
RANDOM()
RANDOM(Seed)
RANDOM(Seed, Range_Start, Range_End, Fraction_Digits)

use 0 to ignore seed
range start/end, either or both, could be negative.
fraction digits, for number of fraction digits in output

RANDOM(0,0,200) => 74 (0 for ignore seed, no fractional digits)

RANDOM(8495,-200,-100,5) => -158.78304 (8495 for seed, negative start and end, with 5 fractional digits)

RANDOM(8495,200,-100,5) => 158.78304 (8495 for seed, with 5 fractional digits, where start is higher than end)

RANDOM(VALUE(DATETIME_FORMAT(NOW(), ‘x’)),1000,2000,7) => 1622.9287305 (use current datetime to seed, with 7 fraction digits)


Ron_Sheridan
Forum|alt.badge.img+5
  • New Participant
  • March 17, 2017

I am looking for a RANDOM Sort capability. I am building a table of Questions to be entered into an app and I want to randomize the questions before they are manually entered or imported.


Forum|alt.badge.img+19
  • Inspiring
  • March 20, 2017

I am looking for a RANDOM Sort capability. I am building a table of Questions to be entered into an app and I want to randomize the questions before they are manually entered or imported.


@Ron_Sheridan if you have any input at all when it comes to development of that app, it would probably be a couple of minutes work for the programmer to shuffle the questions over there before they are shown. :slightly_smiling_face:


Forum|alt.badge.img+10
  • Author
  • Known Participant
  • June 12, 2017

PING. Any update on getting random number generator?


Forum|alt.badge.img+19
  • Inspiring
  • June 15, 2017

PING. Any update on getting random number generator?


Hey @Daniel_Robbins, I thought of something.

If you create a formula with VALUE(RECORD_ID()) you’ll get random numbers for each record. Maybe you can use this a a starting point. With some additional formulas (or even rollups) you should be able to scale it / put it in a certain range.

:slightly_smiling_face:


Forum|alt.badge.img+10
  • Author
  • Known Participant
  • June 15, 2017

Hey @Daniel_Robbins, I thought of something.

If you create a formula with VALUE(RECORD_ID()) you’ll get random numbers for each record. Maybe you can use this a a starting point. With some additional formulas (or even rollups) you should be able to scale it / put it in a certain range.

:slightly_smiling_face:


Thanks. I’ll try that.


Forum|alt.badge.img+19
  • Inspiring
  • June 15, 2017

Thanks. I’ll try that.


You could actually expand that by using the CREATED_TIME() function too.

Grab the numbers from the time portion…

SUBSTITUTE(TIMESTR(CREATED_TIME()), ":", "")

Or only the seconds for example and use that to do an extra calculation, define a random position in the string (maybe with REPT) or whatever.


Avi_Doe
Forum|alt.badge.img+11
  • Known Participant
  • December 11, 2017

Hey @Daniel_Robbins, I thought of something.

If you create a formula with VALUE(RECORD_ID()) you’ll get random numbers for each record. Maybe you can use this a a starting point. With some additional formulas (or even rollups) you should be able to scale it / put it in a certain range.

:slightly_smiling_face:


Sorry but it is not working. With this formula I get the same numbers for several rows…


Forum|alt.badge.img+19
  • Inspiring
  • December 11, 2017

Sorry but it is not working. With this formula I get the same numbers for several rows…


Not very likely. Did you try to refresh the base?


Avi_Doe
Forum|alt.badge.img+11
  • Known Participant
  • December 11, 2017

Not very likely. Did you try to refresh the base?


Yes didn´t help.

May be I am doing something wrong?


Forum|alt.badge.img+19
  • Inspiring
  • December 11, 2017

Yes didn´t help.

May be I am doing something wrong?


Sorry. You are right. :slightly_smiling_face:


Forum|alt.badge.img+19
  • Inspiring
  • December 11, 2017

Yes didn´t help.

May be I am doing something wrong?


What it does is grab numbers from the RECORD_ID. So the numbers you see are random, but not unique.

The other trick (with time) maybe works better in your case.

A combination of the two methods is an option too of course…


Avi_Doe
Forum|alt.badge.img+11
  • Known Participant
  • December 11, 2017

What it does is grab numbers from the RECORD_ID. So the numbers you see are random, but not unique.

The other trick (with time) maybe works better in your case.

A combination of the two methods is an option too of course…


With Record ID you get an unique output. But the outcome looks crazy (many numbers and letters) and so it is not realy usable for an ordernumber.


Forum|alt.badge.img+19
  • Inspiring
  • December 11, 2017

With Record ID you get an unique output. But the outcome looks crazy (many numbers and letters) and so it is not realy usable for an ordernumber.


For order numbers you can also use AT’s Auto Number field. Maybe with something in front of it…


Avi_Doe
Forum|alt.badge.img+11
  • Known Participant
  • December 11, 2017

For order numbers you can also use AT’s Auto Number field. Maybe with something in front of it…


I want to hide the casenumbers to prevent vendors from gathering information out of it. So unfortunately this solution is not working for me.

In software like excel…you have the function RANDOM() for it.


Forum|alt.badge.img+5
  • Inspiring
  • December 12, 2017

I want to hide the casenumbers to prevent vendors from gathering information out of it. So unfortunately this solution is not working for me.

In software like excel…you have the function RANDOM() for it.


Try DATETIME_FORMAT(CREATED_TIME(),'X').

That will give you the Unix timestamp as a string; e.g., ‘1511398652’. You can then chop it up or otherwise obfuscate it as necessary. The results won’t be random, but they should be unique — with one exception: The first three records in a table are created at the time the table is, and all bear the same timestamp.

In theory, you can use 'x' instead of 'X' as the format specifier and get the timestamp with milliseconds included — ‘1360013296123’ is the example from the Airtable help page — but it appears CREATED_TIME() is stored precise to the second only. The results I get with DATETIME_FORMAT(CREATED_TIME(),'x') all have three zeroes as the rightmost three digits.


Avi_Doe
Forum|alt.badge.img+11
  • Known Participant
  • December 14, 2017

Thanks Vann Hall I will use that!


You can Try using function like this : RIGHT(RECORD_ID(),5)


Forum|alt.badge.img+5
  • Inspiring
  • July 16, 2019

Since this thread is still seeing traffic, I should add a link to this recent post, which outlines some ways to generate unique, random[ish] values.


  • New Participant
  • December 11, 2019

I’ve got a similar issue I’m trying to resolve. I would like to be able to pull text entries from another table by LOOKUP or ROLLUP and then randomize the order of those entries, i.e. not alphabetical. Here is the use-case:

We have an episode table, a show table, and a sponsor table. Each show record is first pulling sponsor data from the sponsor table, each episode record is then pulling the aggregated sponsor data from the show table.

Episode 123 - of - Show ABC - has - Sponsor X, Sponsor Y, and Sponsor Z

I would like each new episode record to randomly order the sponsors as it is created. For example:

  • Episode 123 - Show ABC - Sponsor Y, Sponsor X, Sponsor Z
  • Episode 124 - Show ABC - Sponsor Z, Sponsor Y, Sponsor X
  • Episode 125 - Show ABC - Sponsor X, Sponsor Z, Sponsor Y

I’m also utilizing Zapier for some other automation tasks, but haven’t found a great solution there either. Any feedback/help would be greatly appreciated. Thank you!


Justin_Barrett
Forum|alt.badge.img+21

I’ve got a similar issue I’m trying to resolve. I would like to be able to pull text entries from another table by LOOKUP or ROLLUP and then randomize the order of those entries, i.e. not alphabetical. Here is the use-case:

We have an episode table, a show table, and a sponsor table. Each show record is first pulling sponsor data from the sponsor table, each episode record is then pulling the aggregated sponsor data from the show table.

Episode 123 - of - Show ABC - has - Sponsor X, Sponsor Y, and Sponsor Z

I would like each new episode record to randomly order the sponsors as it is created. For example:

  • Episode 123 - Show ABC - Sponsor Y, Sponsor X, Sponsor Z
  • Episode 124 - Show ABC - Sponsor Z, Sponsor Y, Sponsor X
  • Episode 125 - Show ABC - Sponsor X, Sponsor Z, Sponsor Y

I’m also utilizing Zapier for some other automation tasks, but haven’t found a great solution there either. Any feedback/help would be greatly appreciated. Thank you!


You actually may have a useful randomizing tool there in the Code by Zapier app. You (or someone you know/hire) could write a quick bit of code that randomizes the sponsor assignment for a later step to apply in Airtable.


This is my first post, so forgive me if this isn’t helpful. But a workaround I use for generating random numbers is to set up the key column with this formula:

DATETIME_FORMAT(CREATED_TIME(),‘mmsss’)

It pulls the current minute and second the entry was created and displays a set of random digits. This has worked pretty well for my purposes!


Forum|alt.badge.img+10
  • Author
  • Known Participant
  • March 11, 2020

This is my first post, so forgive me if this isn’t helpful. But a workaround I use for generating random numbers is to set up the key column with this formula:

DATETIME_FORMAT(CREATED_TIME(),‘mmsss’)

It pulls the current minute and second the entry was created and displays a set of random digits. This has worked pretty well for my purposes!


Doesn’t work for me as most of my items are essentially created at the same time :frowning: