# Will RANDOMSTRING() ever repeat?

**URL:** <https://community.tulip.co/t/will-randomstring-ever-repeat/5033>\
**Category:** General\
**Tags:** feature-request\
**Created:** [April 20, 2022, 1:13am UTC](https://community.tulip.co/t/will-randomstring-ever-repeat/5033 "2022-04-20T01:13:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![wz2b](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tulip.co/wz2b/32/3833_2.png) [@wz2b](https://community.tulip.co/u/wz2b)\
**Post date:** [April 20, 2022, 1:13am UTC](https://community.tulip.co/t/will-randomstring-ever-repeat/5033/1 "2022-04-20T01:13:34Z")

</div>

Is RANDOMSTRING() something that I never have to worry about there being a collision? What is the algorithm it uses? Is it really random, or is it more like a sequence generator that won’t repeat? Do the 17 bytes include some kind of hashed timestamp so that they can’t repeat?

I’m kind of wishing for an actual [GUID generator](https://en.wikipedia.org/wiki/Universally_unique_identifier).

---

<div class="post-metadata">

**Author:** ![Pete\_Hartnett](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tulip.co/pete_hartnett/32/3678_2.png) [@Pete\_Hartnett](https://community.tulip.co/u/Pete_Hartnett)\
**Post date:** [April 20, 2022, 12:44pm UTC](https://community.tulip.co/t/will-randomstring-ever-repeat/5033/2 "2022-04-20T12:44:46Z")

</div>

Hey @wz2b

The random string function can conceivably return a duplicate value. This can be check for with triggers. The generated random string can be stored to to a variable, then you can check to see if a record exists with that ID, if it does, generate a new random ID.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/agilemfg/original/2X/c/c6e33d92c9c5cc52ab0c36b443835a6ab3a7be32.png)  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/agilemfg/original/2X/d/d94674bc5943506ed2877991d9ed29abb83338df.png)

Having said that, a 17 character case sensitive alpha-numeric has a potential 2.95 X 10^30 unique options. This is ~30 order of magnitude more than the count of atoms in the known universe. Unfortunately generating truly random strings isn’t possible. I reached out to our developers to understand what we are using for the seed value for the random string generator. I will update this thread when I have an answer.

As a little more context - There is a feature in the works right now where records could be created with a random id without the need of an expression, the RANDOM\_STRING() function, etc. This will respect GUID principals and insure no duplicates are generated. The RANDOM\_STRING() function has a place, but shouldn’t be needed to do something as universal as creating records.

Pete

---

<div class="post-metadata">

**Author:** ![Pete\_Hartnett](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tulip.co/pete_hartnett/32/3678_2.png) [@Pete\_Hartnett](https://community.tulip.co/u/Pete_Hartnett)\
**Post date:** [April 20, 2022, 2:14pm UTC](https://community.tulip.co/t/will-randomstring-ever-repeat/5033/3 "2022-04-20T14:14:39Z")

</div>

As promised, here is the update with more technical details -

Random strings are being generated using Meteor’s random number generator which on the browser is implemented using the [Web Crypto API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API). There’s no explicit seeding, it has about 96 bits of entropy (versus 128 for traditional GUID), and the RNG is cryptographically secure, so a repetition is very unlikely.

Some users will add the current time (in epoch) to the random string to eliminate the chance of a repeat, let me know if you need more detail on how to implement this.

Pete

---

<div class="post-metadata">

**Author:** ![wz2b](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tulip.co/wz2b/32/3833_2.png) [@wz2b](https://community.tulip.co/u/wz2b)\
**Post date:** [April 21, 2022, 6:04pm UTC](https://community.tulip.co/t/will-randomstring-ever-repeat/5033/4 "2022-04-21T18:04:16Z")

</div>

Thanks, that’s good for now! I don’t mind adding something to the string, that seems reasonable, but based on your description I’m not even sure it’s necessary. Long term I think Tulip could consider other ways to handle this, for the use case of generating history/event logs that need truly unique IDs. I agree the probability of a collision is very very low. But, if it DID happen it would be pretty confusing.

---

<div class="post-metadata">

**Author:** ![cpuzzo](https://avatars.discourse-cdn.com/v4/letter/c/65b543/32.png) [@cpuzzo](https://community.tulip.co/u/cpuzzo)\
**Post date:** [September 13, 2024, 1:51pm UTC](https://community.tulip.co/t/will-randomstring-ever-repeat/5033/5 "2024-09-13T13:51:37Z")

</div>

Hi Pete, was the feature to generate non-duplicate random strings without the need for an expression ever implemented? If so, can you provide a link to an appropriate KBA so I can get additional details?

---

<div class="post-metadata">

**Author:** ![Pete\_Hartnett](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tulip.co/pete_hartnett/32/3678_2.png) [@Pete\_Hartnett](https://community.tulip.co/u/Pete_Hartnett)\
**Post date:** [September 13, 2024, 2:29pm UTC](https://community.tulip.co/t/will-randomstring-ever-repeat/5033/6 "2024-09-13T14:29:20Z")

</div>

Hey @cpuzzo -

Given the _almost_ guarenteed uniqueness, this isn’t something we have added. If this level of entropy isn’t enough, adding on a timestamp will add another layer of guarentee.

> a 17 character case sensitive alpha-numeric has a potential 2.95 X 10^30 unique options. This is ~30 order of magnitude more than the count of atoms in the known universe.

Importantly, you can check to see if an ID exists in a table, and (at the cost of complexity) you can check this if there are serious concerns still about uniqueness.

Pete
