How to generate a random number?

Hi all,

When a user signs up, I want to save a random 6 digit number to their DB which they can then use as an invite code to invite others. How do I generate the random number?

Hi Darren,
Is the invite code data type “Number”?
Search for this action calculate formula > generate random string.

Good luck!

Thank you, that is almost there but I am left with red text, I need to add something to the condition? The code is of type ‘number’ in the DB so I am unsure what I am supposed to add?

Make the “code” a text instead of a number. Maybe that will help!

or convert the string to a number (assuming the Invite Code field is a number)… although if you want it to be 6 digits then it will have to be a text. So yeah, change the field to text in that case.

Of course, none of this takes into account the issue of duplicate numbers here, which may or may not be an issue, depending on what you’re planning to do with those generated numbers.

Yes that solved it. Thank you!

1 Like

@adamhholmes

although if you want it to be 6 digits then it will have to be a text. So yeah,change the field to text in that case.

Yes, have changed the field to text.

Of course, none of this takes into account the issue of duplicate numbers here, which may or may not be an issue, depending on what you’re planning to do with those generated numbers.
[/quote]

Ah yes, thank you for pointing that out. I will have a think on this.