Forum Academy Marketplace Showcase Pricing Features

Generate random combination of letters and numbers fith fixed length

Well that kind of puts a dent in that theory (ofc I’m not saying it’s wrong). You tried both manual entry and signing a user up from the front-end, same result. I signed my users up from front-end but I manually changed the ID value to check the 999-1000 effect. I guess there’s something on your side. You could share your editor if you’d like someone to check it further.

Maybe I am misunderstanding how bubble arguments work, but I don’t think we could use the unique ID any way, as I would need to use this information for dynamic data. So I couldn’t use the unique ID as a customer ID, because I then wouldn’t be able to get workflows to add this to invoices later, correct?

Sure you can. You can always cross-reference data if you set your DB up correctly, where you define a new field as type [other field], e.g.
I have orders that are based on creations, that are created by users. So if you set it up correctly, you can use thing [Order]'s Creation’s user and all their fields respectively.

The problem I am seeing with ‘random strings’ is duplication. Wouldn’t I have to set up a bunch of other workflows to check that it is unique?

I don’t think so. Not exactly sure how to set it up just thinking about it now when reading your post but you should definitely be able to solve it. I think @mishav’s third party suggestion is valid. If you want to be really sure, perhaps there’s a possibility to use UUIDs through an API somewhere. You can read more here. (I think especially the part with

In other words, only after generating 1 billion UUIDs every second for the next 100 years, the probability of creating just one duplicate would be about 50%.)

helps to put the duplication error worries to rest.)

If you’d go with bubble’s “generate string”, I guess it’d be up to @emmanuel to comment on the random string generator’s technical specs of generating randomness. However and from a basic probability point of view, the more character’s you use, the less chance of duplication. In addition, the actual probability of duplication when generating a random string with enough characters, using letters, non-cap letters, numbers and special characters is "practically 0-ish". :wink:

2 Likes

That’s correct. The algorithm is pseudo random and cannot guarantee strict randomness. And definitely cannot guarantee unique strings (not sure how that would work…)

1 Like

This is all really interesting. One of the hindering details is human readability/utility.

For example, if a user needs to search customers by ID. In this situation, more variables (letters, caps, length, etc.) that increase unique probability, would at the same time make data entry more difficult.

I am wondering if sequential numbers should be a function in menu dropdowns?

For the discussion of unique IDs, it would be nice, but not required. However, anything dealing with finance or accounting, this is necessary. Some countries require it for tax purposes, and eventually, ill need to do it for invoices. Super important to have sequential invoice numbers for order tracking in our industry.

I have never known what your app was about. :slight_smile:

If your talking about a user ID number, I’d say you could go with whichever solution that suits your needs. Instead of searching by ID; first name last name or email or something would be a lot easier. However, that doesn’t mean you can’t use the ID’s for many other things.

For building a finance system, the requirements are obviously tougher. I’m in EU and I know by law you’re required to sequence your invoices. It’s not a problem. I made it work. You just have to look through your app to find the error giving you the result of 1, and not the sequence.

1 Like

Great thread. There was some mention of ensuring uniqueness and to achieve that with a workflow. However, I couldn’t find any solution herein.

I am generating a random string once per user. It is intended that the string is unique to that user and will never be assigned to anyone else. At the point of generation, I want to be able to check all previously generated strings to ensure that the new one is in fact unique. If it is not, then I want to re-generate it until it is unique and then assign it to the current user.

Any thoughts?

If Bubble’s random function is called multiple times within the same workflow, the same string is returned each time, perhaps by a huge coincidence.

If calling an external API, such as mathjs or random.org, there might be a noticeable delay if the user is waiting on several API calls sequentially. A set of random strings could be retrieved at the same time into a list (not shareable with other users) to make regeneration more efficient.

Having a list of randoms might also make the retry loop easier.

Then there is the corner case where every random in the set has already been taken, do you start over, have a retry limit, or give the user a retry button, or abort and abandon the death star?

Hey all, regarding this topic, please check out a plugin I developed last night:

All the best.

Did you ever figure out how to create unique IDs that don’t duplicate? I’ve tried “when condition is true” workflows, recursive custom workflows (throws a bubble system error) and backend APIs to no avail…

2 Likes

Struggling with this at the moment too. I am generating strings of 4 characters including letters and numbers. If I’m correct that means there’s roughly 1.6 million combinations, however I can’t find how to ensure uniqueness…

Anyone? :smiley:

I ended up creating my own solution and documented the entire process here: Creating random unique IDs that do not duplicate

1 Like

I am still scratching my head to have unique random numbers between a start series say 12000 and end series 12500, @daniel10 had it nicely setup, however as @mishav said that random numbers throws repeated numbers more often than should be.

Can you simply have a series running between 1-500 and then add 12000 to it after the fact?

1 Like

Wow Smart ! @daniel10 Experience counts, and happy to see experienced people coming to help new bubblers.
I appreciate your time.
Thanks again