Search for duplicate random string in a wokflow

Hi all,

I am trying to work something out and struggling so would appreciate any help anyone can offer.

Whilst doing testing on creation of random strings and saving as a ‘random code’, I am finding it difficult to search for the ‘random code’ I have created without having an input field.

So I have created my list and a button to generate the random string.

Then my workflow…

As you can see, when I want to search to see if the ‘random code’ already exists. As I don’t have an input to check, how can I search for the random string?

I have thought about adding the ‘random code’ to a custom state on the button and then using that, which works, but it just feels too ‘hacky’ and was wondering if anyone else had any better ideas.

Thanks in advance for any advice.

1 Like

Hi there, @craig.morris… for what it’s worth, I don’t think the custom state idea is too hacky, and if I was doing what you described, I would probably go the custom state route, too. I mean, you want to check the random string against existing strings before you create a new thing in the Random Code Test data type, and I’m not sure how you would do it without generating the new code and putting it somewhere so you can check it. So, again, the custom state idea seems like a reasonable approach to me.



Hi Mike,

I appreciate the reply. Yeah the custom state route seems to be the only solution I could find but thought I would give it a shot and see if anyone had any other solutions. I guess I will stick with it if that’s the easiest/best solution that you can recommend.

Thanks again.

1 Like

If you’d like to do this in a much more reliable and performant way so that you don’t even have to check for collisions, you can use the little-known and underappreciated “nanoID” feature of List Shifter, which produces cryptographically random unique IDs that are - at proper lengths - for all intents and purposes *universally unique" across literally the entire lifetime of the universe. Here’s a demo page:

(Also, open the console to see Debug Buddy tell you how many milliseconds it took to generate one million nanoids.)

BUT, even if you just want to know if your list of “random” values contains any duplicates, that’s just (let’s say your list of random values is my_random_list):

my_random_list :count is my_random_list : unique elements :count

This will be true if there are no duplicates in the list, false otherwise.

EDIT: This should be obvious, but then likewise if you want to assess whether an individual value in your RG of random values is unique, you can do (in the cell) something like:

RG's list of random values :minus item this cell's item :count is (RG's :count -1)

(You may need the parentheses feature turned on to do this as a one-liner… not sure off the top of my head.)

This will be true if the value is unique (because if there’s only 1 of them the count will be one less once the item is removed from the full list. If there is more than 1 of the same item in the list, this expression will be false because more than 1 item was present in the list and has been removed more than once.

(This is a way of saying: The set-like behavior of Bubble list operators isn’t always something to be worked around, but something to be embraced.)

1 Like

Hi Keith,

This is interesting, I didn’t know this existed. I will have to look into this as it will be lists of codes that I need in the near future. I appreciate your ideas.

Thank you

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