# Generate random combination of letters and numbers fith fixed length

**URL:** <https://forum.bubble.io/t/generate-random-combination-of-letters-and-numbers-fith-fixed-length/6587>\
**Category:** Need help\
**Created:** [October 3, 2016, 10:18am UTC](https://forum.bubble.io/t/generate-random-combination-of-letters-and-numbers-fith-fixed-length/6587 "2016-10-03T10:18:44Z")\
**Posts on this page:** 1\
**Showing post:** 17

<div class="post-metadata">

**Author:** ![mishav](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/mishav/32/6420_2.png) [@mishav](https://forum.bubble.io/u/mishav)\
**Post date:** [October 27, 2016, 2:57am UTC](https://forum.bubble.io/t/generate-random-combination-of-letters-and-numbers-fith-fixed-length/6587/17 "2016-10-27T02:57:30Z")

</div>

> [@jameslusk](#):
>
> And I can’t see how it is a DB refresh issue

This is possible, if for example you recently added the field, or manually edited the “999” it wouldn’t have given the UI’s cached database values a reason to update.

Incrementing the max ID is a vulnerable method; when two users are created at roughly the same time they might return the same max ID, and caching makes the window of error even larger.

Note that each row already has a unique ID, that looks like:  
1477501458054x757140743779018500

I take it you want something useful for people to read though!

Ideally it would be possible to use a database sequence, or PostgreSQL’s serial number type, to guarantee a unique number, perhaps the Bubble developers can make it available?

> **[8.1. Numeric Types](https://www.postgresql.org/docs/9.6/datatype-numeric.html)**
>
> 8.1. Numeric Types # 8.1.1. Integer Types 8.1.2. Arbitrary Precision Numbers 8.1.3. Floating-Point Types 8.1.4. Serial Types Numeric types consist of …

_Edit_: there is a workaround posted here, still allows collisions but less likely than if sequential:

> [@Format Unique ID Differently?](http://forum.bubble.io/t/format-unique-id-differently/3113/12):
>
> In the meantime, you could use mathjs to ask for a random number, round it and call this via the api [http://api.mathjs.org/v1/?expr=round(random(10000,99999)](http://api.mathjs.org/v1/?expr=round(random(10000,99999))) Use the api plugin to make the call

_Edit again_: Could use Bubble’s random number generator function instead of calling the API.

---

_[View the full topic](https://forum.bubble.io/t/generate-random-combination-of-letters-and-numbers-fith-fixed-length/6587)._
