Creating a unique random string for a username

Hi all,

I am trying to create a unique random number string for use in a default username on signup (eg. User123456789). So far I’ve just been using the built-in string generator, but it is my understanding that there is a chance they will not be unique?

How can I either:
a) make unique strings every time
b) verify by comparing with the database that the generated username is unique before inserting it

Let me know if I need to provide any more information!

Cheers

You can use the Calculate Formula method then check that with your database to make sure that there isn’t one that already exists, if it does redo it

Ok! Perfect. How?

For some reason this is very difficult. On the surface concept is easy. I don’t even need it be truly random but Unique for sure. There is no UNIQUE constraint option that I can tell. Maybe I’m asking the wrong question. I just need a 6 or 7 digit unique code that appears random or starts at 100000

Hello!

Hope this helps! :slight_smile:

1 Like

I’m definitely following you here! Thank you. Most importantly, is the random string generated here truly Unique ?

What is the chance of a long random string made up of combined numbers, letters and special characters to be repeated?

I leave it to you to reach your own conclusion :grinning:

Certainly would be highly unlikely with that many potentional combinations. Really trying to dial in a way to check for the unique number, if it exists try again. Unfortunately this use case has to be numbers only and is limited in string length. The trouble I am having is that there will be times that the random string matches ( no way around it) so how do you check if the random string exists then try again until it does not? Or is there a way to eliminate the existing numbers from the possible returns of the random number generator? I’ve seen a ton of people asking this question but it runs into the looping problem. Ideally, any numbers already in the data base would no longer be an option in the unique set returned by the generator.

Create a thing for every instance. Then inside build your random string as a text field. For function use the thing’s unique id. For displaying to the user … use the text.

2 Likes

If you use a backend workflow to create (or update) the thing, then you can loop it, and therefore check for duplication.

There are quite a few ways ways you can achieve the same thing (depending on your use case), but as an example:

Create a backend workflow with 2 actions: 1 that will create and set a new random code for the ‘thing’ in question, and then another that will schedule itself to run again. The entire workflow should have a conditional to run only when the random code in question is a duplicate (i.e. search for the ‘code’: count >1).

Create another workflow (either in the browser or on the backend) to initially create the thing and set the unique code, and then trigger the backend workflow created above (that will check if the code already exist and, if it does, create a new one, then check it again, and so on).

That way, you will create your thing and assign a random unique code to it, then check that the code didn’t already exist and, if it did then immediately replace it with another one.

7 Likes

Thank you for sticking with me

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.