# Need help with Generating 6 digit unique random number string

**URL:** <https://forum.bubble.io/t/need-help-with-generating-6-digit-unique-random-number-string/148636>\
**Category:** Database\
**Created:** [April 28, 2021, 2:49pm UTC](https://forum.bubble.io/t/need-help-with-generating-6-digit-unique-random-number-string/148636 "2021-04-28T14:49:17Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![netwayerbusiness1](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/netwayerbusiness1/32/92732_2.png) [@netwayerbusiness1](https://forum.bubble.io/u/netwayerbusiness1)\
**Post date:** [April 28, 2021, 2:49pm UTC](https://forum.bubble.io/t/need-help-with-generating-6-digit-unique-random-number-string/148636/1 "2021-04-28T14:49:17Z")

</div>

Does anyone know a reliable workflow to generate a unique 6 digit number string? I already tried calculate random string on my 4000 rows and lots of them had duplicate values. I needed this for the account code that will be tagged with the members name in the database. Please help me out, Im so stucked on this.

---

<div class="post-metadata">

**Author:** ![anon26152888](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@anon26152888](https://forum.bubble.io/u/anon26152888)\
**Post date:** [April 28, 2021, 2:53pm UTC](https://forum.bubble.io/t/need-help-with-generating-6-digit-unique-random-number-string/148636/2 "2021-04-28T14:53:57Z")

</div>

This is what you can do. And what I use to generate a string for a 2-step verification system:

 ![image](https://us1.discourse-cdn.com/bubble/original/3X/c/d/cd9363b2be4ec58a22a833ad43ae9c9557f2258a.png)  
Does that answer your question?

Sincerely,  
Nathan

---

<div class="post-metadata">

**Author:** ![netwayerbusiness1](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/netwayerbusiness1/32/92732_2.png) [@netwayerbusiness1](https://forum.bubble.io/u/netwayerbusiness1)\
**Post date:** [April 28, 2021, 2:59pm UTC](https://forum.bubble.io/t/need-help-with-generating-6-digit-unique-random-number-string/148636/3 "2021-04-28T14:59:51Z")

</div>

Thank you Nathan, but this never seems to solve my problem. This is what I actually did in the workflow in every valid registration except for the “Only when” condition which I dont think will help in preventing strings to duplicate in over 4000 rows and counting…

---

<div class="post-metadata">

**Author:** ![anon26152888](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@anon26152888](https://forum.bubble.io/u/anon26152888)\
**Post date:** [April 28, 2021, 3:01pm UTC](https://forum.bubble.io/t/need-help-with-generating-6-digit-unique-random-number-string/148636/4 "2021-04-28T15:01:10Z")

</div>

Could you send me a picture of your workflows?

---

<div class="post-metadata">

**Author:** ![netwayerbusiness1](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/netwayerbusiness1/32/92732_2.png) [@netwayerbusiness1](https://forum.bubble.io/u/netwayerbusiness1)\
**Post date:** [April 28, 2021, 3:06pm UTC](https://forum.bubble.io/t/need-help-with-generating-6-digit-unique-random-number-string/148636/5 "2021-04-28T15:06:30Z")

</div>

![workflow1](https://us1.discourse-cdn.com/bubble/original/3X/c/e/ce41c2f1d2031f592a17e2ca8ac7dba97dc96dee.jpeg)

There are a lot more data going down and I did not have any “Only when” condition on this

---

<div class="post-metadata">

**Author:** ![anon26152888](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@anon26152888](https://forum.bubble.io/u/anon26152888)\
**Post date:** [April 28, 2021, 3:09pm UTC](https://forum.bubble.io/t/need-help-with-generating-6-digit-unique-random-number-string/148636/6 "2021-04-28T15:09:48Z")

</div>

Hmmmmm… Seems really confusing and harder than I thought.

---

<div class="post-metadata">

**Author:** ![netwayerbusiness1](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/netwayerbusiness1/32/92732_2.png) [@netwayerbusiness1](https://forum.bubble.io/u/netwayerbusiness1)\
**Post date:** [April 28, 2021, 3:12pm UTC](https://forum.bubble.io/t/need-help-with-generating-6-digit-unique-random-number-string/148636/7 "2021-04-28T15:12:13Z")

</div>

Yeah, this data is from a registration form. Rest of the data inputs are okay. Only this 6 digit string that I need to be NOT DUPLICATING no matter how many new registrations are being pushed into the DB.

---

<div class="post-metadata">

**Author:** ![anon26152888](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@anon26152888](https://forum.bubble.io/u/anon26152888)\
**Post date:** [April 28, 2021, 3:13pm UTC](https://forum.bubble.io/t/need-help-with-generating-6-digit-unique-random-number-string/148636/8 "2021-04-28T15:13:53Z")

</div>

What do you mean by duplicating? Like whats happening when it duplicates?

---

<div class="post-metadata">

**Author:** ![netwayerbusiness1](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/netwayerbusiness1/32/92732_2.png) [@netwayerbusiness1](https://forum.bubble.io/u/netwayerbusiness1)\
**Post date:** [April 28, 2021, 3:14pm UTC](https://forum.bubble.io/t/need-help-with-generating-6-digit-unique-random-number-string/148636/9 "2021-04-28T15:14:17Z")

</div>

unless ofcourse if all the possible 6 digit combination is used up.

---

<div class="post-metadata">

**Author:** ![netwayerbusiness1](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/netwayerbusiness1/32/92732_2.png) [@netwayerbusiness1](https://forum.bubble.io/u/netwayerbusiness1)\
**Post date:** [April 28, 2021, 3:16pm UTC](https://forum.bubble.io/t/need-help-with-generating-6-digit-unique-random-number-string/148636/10 "2021-04-28T15:16:40Z")

</div>

Member 1 = 000001  
Member 2 = 000001

instances like that should not happen. bcoz each member must have a unique 6digit code for itself

---

<div class="post-metadata">

**Author:** ![anon26152888](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@anon26152888](https://forum.bubble.io/u/anon26152888)\
**Post date:** [April 28, 2021, 3:17pm UTC](https://forum.bubble.io/t/need-help-with-generating-6-digit-unique-random-number-string/148636/11 "2021-04-28T15:17:24Z")

</div>

Did you know when each user signs up they get their own unique id already generated by bubble?

---

<div class="post-metadata">

**Author:** ![netwayerbusiness1](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/netwayerbusiness1/32/92732_2.png) [@netwayerbusiness1](https://forum.bubble.io/u/netwayerbusiness1)\
**Post date:** [April 28, 2021, 3:20pm UTC](https://forum.bubble.io/t/need-help-with-generating-6-digit-unique-random-number-string/148636/12 "2021-04-28T15:20:41Z")

</div>

yes but that’s a long string. Is it possible to trim that into 6 digits without having the possibility of duplicating?

---

<div class="post-metadata">

**Author:** ![anon26152888](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@anon26152888](https://forum.bubble.io/u/anon26152888)\
**Post date:** [April 28, 2021, 3:21pm UTC](https://forum.bubble.io/t/need-help-with-generating-6-digit-unique-random-number-string/148636/13 "2021-04-28T15:21:47Z")

</div>

I dont think so with your situation. Plus with whatever your creating there could be a lot of users and then you would run out. Trust bubble on this one.

---

<div class="post-metadata">

**Author:** ![adamhholmes](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/adamhholmes/32/100510_2.png) [@adamhholmes](https://forum.bubble.io/u/adamhholmes)\
**Post date:** [April 28, 2021, 3:22pm UTC](https://forum.bubble.io/t/need-help-with-generating-6-digit-unique-random-number-string/148636/14 "2021-04-28T15:22:08Z")

</div>

This is a question that comes up quite regularly on the forum (there are quite a few answers too)…

There are a few ways to go about it depending on your setup, but basically, in order to check the uniqueness of a calculated string you’ll need to set up a ‘loop’, or a recursive workflow, to check if the generated number is unique, and then generate a new one if it’s not.

In native Bubble you can’t to this in the browser, so it has to be done on the backend, but it’s fairly simple to do.

Simply create a backend workflow with 2 actions, 1 that will generate and set a new random number for the ‘thing’ in question, and another that will schedule itself to run again.

Have an ‘only when conditional’ on the entire workflow so that it will only run when the random number IS a duplicate (i.e. its count \> 1) (you’ll need to run a DB search to establish this).

Then in your browser workflow, generate the initial random string, then schedule the backend workflow to run right away.

The backend workflow will check to see if it’s a duplicate and, if it is, it will generate a new random string. It will continue to check that it is not a duplicate until a unique random string has been generated, then will stop running.

---

<div class="post-metadata">

**Author:** ![netwayerbusiness1](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/netwayerbusiness1/32/92732_2.png) [@netwayerbusiness1](https://forum.bubble.io/u/netwayerbusiness1)\
**Post date:** [April 28, 2021, 3:26pm UTC](https://forum.bubble.io/t/need-help-with-generating-6-digit-unique-random-number-string/148636/15 "2021-04-28T15:26:22Z")

</div>

there could be a few thousands but not a over a million I believe as this app is created specifically for an organization which membership is limited within a specified area. Pretty sure all possible members will be able to register without using up all the possible 6 digit number combinations. I just need them to NOT DUPLICATING. Each new registration should generate a string that does not exist yet in the DB

---

<div class="post-metadata">

**Author:** ![anon26152888](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@anon26152888](https://forum.bubble.io/u/anon26152888)\
**Post date:** [April 28, 2021, 3:31pm UTC](https://forum.bubble.io/t/need-help-with-generating-6-digit-unique-random-number-string/148636/16 "2021-04-28T15:31:01Z")

</div>

I’d hate to say it but I dont know how to help you. I dont think others have an issue with it being long. I personally dont think that it’s too long. Hopefully you figure it out or take my advice to trust bubble.

Best of luck,  
Nathan

---

<div class="post-metadata">

**Author:** ![anon26152888](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@anon26152888](https://forum.bubble.io/u/anon26152888)\
**Post date:** [April 28, 2021, 3:33pm UTC](https://forum.bubble.io/t/need-help-with-generating-6-digit-unique-random-number-string/148636/18 "2021-04-28T15:33:23Z")

</div>

He is trying to make is own and make it 6 digits. But it wont make a new one for each user.

---

<div class="post-metadata">

**Author:** ![netwayerbusiness1](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/netwayerbusiness1/32/92732_2.png) [@netwayerbusiness1](https://forum.bubble.io/u/netwayerbusiness1)\
**Post date:** [April 28, 2021, 3:36pm UTC](https://forum.bubble.io/t/need-help-with-generating-6-digit-unique-random-number-string/148636/20 "2021-04-28T15:36:43Z")

</div>

Yes, the shortest way to say it. sorry I took the long way.

---

<div class="post-metadata">

**Author:** ![jared.gibb](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/jared.gibb/32/123329_2.png) [@jared.gibb](https://forum.bubble.io/u/jared.gibb)\
**Post date:** [April 28, 2021, 3:40pm UTC](https://forum.bubble.io/t/need-help-with-generating-6-digit-unique-random-number-string/148636/21 "2021-04-28T15:40:13Z")

</div>

Sounds like you’ll need a recursive workflow that works like this

Create user  
Trigger custom workflow

Custom workflow  
Create randomstring  
Modify current users randID  
-_IF a search for User’s randID **does not** contain randomstring from step 1_  
Trigger custom work  
-_IF a search for User’s randID **does** contain randomstring from step 1_

Have you set one up before?

This workflow would call itself u til the conditional on step 2 is satisfied.

---

<div class="post-metadata">

**Author:** ![netwayerbusiness1](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/netwayerbusiness1/32/92732_2.png) [@netwayerbusiness1](https://forum.bubble.io/u/netwayerbusiness1)\
**Post date:** [April 28, 2021, 3:43pm UTC](https://forum.bubble.io/t/need-help-with-generating-6-digit-unique-random-number-string/148636/22 "2021-04-28T15:43:41Z")

</div>

Im giving this a try. I have a feeling this will get me what I want. Thankyou very much to all of you.

[Next page](https://forum.bubble.io/t/need-help-with-generating-6-digit-unique-random-number-string/148636.md?page=2)
