![]() And since there were only going to be 2-10 options per question, I didn't need those IDs to be very long either. ![]() As a workaround, though, prepend client-generated IDs with userid, so that adversary/faulty client can only collide with themselves (and handle that on server side). ![]() Since these IDs are generated on the front end, I didn't want to use a dedicated ID library to achieve it. There's a big problem in your architecture, unrelated to UUIDs - client may intentionally generate colliding IDs. This method supports the random number generator. But sometimes, you just need a short unique ID.Īnd maybe you don't want to use another JavaScript library for it.įor example, I was recently putting together a quick quiz, and I need each of the answer options to have unique IDs. Random UUID can be easily generated with the help of the randomUUID method of global prototype crypto. Here's the function I use to create a random unique ID in JavaScript, and an explanation of how it works.Ĭreating unique random IDs can be a pretty complex task, and there are dedicated libraries like uuid that can handle this for you.īut sometimes, those IDs can end up being pretty long, with timestamps and other details involved. If you need a simple short ID and don't have any complex requirements for it, then a simple JavaScript function could be all you need. Generate v1 UUIDs Install the uuid library: npm install uuid3.4.0 Run it through browserify: browserify nodemodules/uuid/index.js -s uuid >.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |