Skip to main content

Auto Generate Random Number

  • Feb 18, 2020 3:50 PM UTC
  • 9 replies
  • 432 views

Hello all,

I’m trying to figure out a way to randomly generate a 6 digit randomized number for confirmation use on future bookings. So far I’ve come up with using ‘Autonumber’ and a formula to add six 0’s as a prefix. However, I’d like the number to be completely random.

Does anyone have any input on how to achieve this or if it’s possible on Airtable?

Thank you!
Alex

This topic has been closed for replies.

9 replies

Forum|alt.badge.img+14

Does it have to be 6 digits? Using the record id is a good way of generating random codes that are required for identifying the record for later use. They are alphanumeric though and, even if you strip out the preceding “rec”, they are 14 characters long.


  • Author
  • Participating Frequently
  • Feb 18, 2020 6:01 PM UTC

Does it have to be 6 digits? Using the record id is a good way of generating random codes that are required for identifying the record for later use. They are alphanumeric though and, even if you strip out the preceding “rec”, they are 14 characters long.


Not at all! That’s a great idea though!! Then I can use a formula to strip away the letter and return #'s only. I think that doable. Is it not?

Thanks!


  • Participating Frequently
  • Feb 18, 2020 11:50 PM UTC

Not at all! That’s a great idea though!! Then I can use a formula to strip away the letter and return #'s only. I think that doable. Is it not?

Thanks!


I’m actually not sure if you can…just did a sweep of the formulas and I couldn’t really find a way. The Record ID way might not work if you need a uniform number of digits… it would be great if the Autonumber field type just had a variant for “Unique ID” where you could specify number of digits.


  • Author
  • Participating Frequently
  • Feb 19, 2020 12:17 AM UTC

I’m actually not sure if you can…just did a sweep of the formulas and I couldn’t really find a way. The Record ID way might not work if you need a uniform number of digits… it would be great if the Autonumber field type just had a variant for “Unique ID” where you could specify number of digits.


Hey Nick - you’re right , it doesn’t work. I guess a sequential order of numbers will have to do the trick.


  • Participating Frequently
  • Feb 19, 2020 3:19 AM UTC

Hey Nick - you’re right , it doesn’t work. I guess a sequential order of numbers will have to do the trick.


You might be able to use the scripting block but my JavaScript is about as good as my Portuguese (which is not say não muito bom)


  • Author
  • Participating Frequently
  • Feb 21, 2020 10:15 PM UTC

You might be able to use the scripting block but my JavaScript is about as good as my Portuguese (which is not say não muito bom)


Didn’t know that was an option. Will have to look into it.

On another note, do you happen to know if it’s possible to set a formula to return the following:

IF “Trip Name” is “Paris”, AND departure date is greater or equal to 90 days, AND “Room Type” is “Single Room”, then return “Trip Deposit Amount” + $350, IF “Trip Name” is “Paris”, AND departure date is greater or equal to 90 days, AND “Room Type” is “Shared Room”, then return “Trip Deposit Amount”, IF “Trip Name” is “Paris”, AND departure date is less than 90 days, AND “Room Type” is “Single Room”, then return “Trip Full Amount” + $350, IF “Trip Name” is “Paris”, AND departure date is less than 90 days, AND “Room Type” is “Shared Room”, then return “Trip Full Amount”, ELSE “Blank”

Trying to set up this variable for booking vacations based on variable dates and room types.

Do you have any insight on which formulas to use to get this?

Thanks!


kuovonne
Forum|alt.badge.img+29
  • Brainy
  • Feb 21, 2020 11:54 PM UTC

Didn’t know that was an option. Will have to look into it.

On another note, do you happen to know if it’s possible to set a formula to return the following:

IF “Trip Name” is “Paris”, AND departure date is greater or equal to 90 days, AND “Room Type” is “Single Room”, then return “Trip Deposit Amount” + $350, IF “Trip Name” is “Paris”, AND departure date is greater or equal to 90 days, AND “Room Type” is “Shared Room”, then return “Trip Deposit Amount”, IF “Trip Name” is “Paris”, AND departure date is less than 90 days, AND “Room Type” is “Single Room”, then return “Trip Full Amount” + $350, IF “Trip Name” is “Paris”, AND departure date is less than 90 days, AND “Room Type” is “Shared Room”, then return “Trip Full Amount”, ELSE “Blank”

Trying to set up this variable for booking vacations based on variable dates and room types.

Do you have any insight on which formulas to use to get this?

Thanks!


@Alex_Cristian

Yes, it is possible.

Here is one method: put each situation in its own IF, and then concatenate them using the & operator.

IF( AND(condition1, condition2, condition3), 
    {Trip Deposit Amount} + 350, 
    ""
) & 
IF( AND(condition4, condition5, condition6), 
    {Trip Deposit Amount}, 
    ""
) & 
IF( AND(condition7, condition8, condition9), 
    {Trip Full Amount} + 350, 
    ""
) & 
IF( AND(condition10, condition11, condition12), 
    {Trip Full Amount}, 
    ""
) 

I also suggest using a code editor, such as Notepad++ to write your formula. It will make things like matching up opening and closing parentheses much easier. You can also break the formula up across multiple lines.

By the way, when you have a new question on a different issue, it is best to start a new topic so that it is easier for other users to know that you have a new issue.


  • Author
  • Participating Frequently
  • Feb 22, 2020 4:08 AM UTC

@Alex_Cristian

Yes, it is possible.

Here is one method: put each situation in its own IF, and then concatenate them using the & operator.

IF( AND(condition1, condition2, condition3), 
    {Trip Deposit Amount} + 350, 
    ""
) & 
IF( AND(condition4, condition5, condition6), 
    {Trip Deposit Amount}, 
    ""
) & 
IF( AND(condition7, condition8, condition9), 
    {Trip Full Amount} + 350, 
    ""
) & 
IF( AND(condition10, condition11, condition12), 
    {Trip Full Amount}, 
    ""
) 

I also suggest using a code editor, such as Notepad++ to write your formula. It will make things like matching up opening and closing parentheses much easier. You can also break the formula up across multiple lines.

By the way, when you have a new question on a different issue, it is best to start a new topic so that it is easier for other users to know that you have a new issue.


Thanks so much! This was perfect!! I’ve never used the concatenate function before, but now that I have, it makes so much more sense to make use it. So awesome! Thanks again!


sally_andsundry
Forum|alt.badge.img+10

Hey! I made a post about how to generate consistently random numbers!

Check me out: https://www.linkedin.com/feed/update/urn:li:activity:7269370700782542848/