PricingDocsAcademy
Bluesky ...
Fri, Dec 13, 9:38 AM

Best practice on creating a unique alphanumeric id

  • /attachments/1305100023125770272/1305101272730570833/toddle.dev_projects_jointhelist_branches_waitlist_components_HomePage_leftpaneldesignrightpanelstylecanvas-width1208canvas-height800selectionformulas.SnatFe.formula_1.png

    Tom Ireland

    1 month ago

    I'm looking to create a unique ID to use in a URL but don't want to use UUID. A bit like how toddle creates a unique id for nodes and classes.

    I usually create them by generating a random number in a formula, multiplying it by 100000 and then round it, which usually produces a 6 digit unique ID.

    My thinking is just to convert the number output to a string and then encode it as base64.

    Would that work? Anything I should be mindful of and is there a better way?
    toddle.dev_projects_jointhelist_branches_waitlist_components_HomePage_leftpaneldesignrightpanelstylecanvas-width1208canvas-height800selectionformulas.SnatFe.formula_1.png
  • Tom Ireland

    1 month ago

    Best practice on creating a unique alphanumeric id
  • Armand

    1 month ago

    Alternatively you could also use the Now node to get a unix timestamp. Although it will be a bit longer than 6 digits.
  • Tom Ireland

    1 month ago

    Good shout, Armand! I did think about that but wanted to rule out the possibility of someone clicking at the exact same moment. Unlikely but worth bearing in mind.
  • Armand

    1 month ago

    Unlikely indeed if it is in ms, but not impossible. You can always append or prepend with a single digit random number. So then there is a 1 in 10 chance of getting the same string of numbers two people click at the exact same time.

    But perhaps there are easier ways of doing this ๐Ÿ™‚
  • Tom Ireland

    1 month ago

    Aye, good suggestions. Loads of ways to skin a cat I guess.
  • Max

    1 month ago

    Hey Tom! What is the use case for that? Those approaches won't generate UUIDs, but only "probably-unique-in-the-current-context" ids
  • Tom Ireland

    1 month ago

    I'm trying to create a unique id for a url parameter. I could auto-generate a uuid in the db when the record is created but that's quite long to share (when sharing the URL with others containing the unique id). I just wanted to create something relatively small but that will still remain unique.
  • Max

    1 month ago

    If it has to be unique, you need to create it in the backend or use a library.
  • Personally, I would do it in the backend
    ๐Ÿ‘1

Stop scrolling. Start building.

toddle is a visual web app builder that rivals custom code โ€” but accessible to your entire team!

Try toddle โ€” it's free!

ยฉ Copyright 2024 toddle. All rights reserved.