Utils: UID returns invalid UUID



  • It would be nice if uid() would deliver a valid uuid as mentioned here:
    https://stackoverflow.com/a/105074/484766



  • If you want a valid UUID, please use a UUID library and create them with it.

    Scott



  • It certainly would be easy and fast for Quasar Framework to support UUID v4, since literally all you have to do is put a 4 in one spot, since the rest is random… seems like quite an easy thing to do and not sure why it wasn’t done in the first place. Suggesting importing an entire library because Quasar doesn’t put a 4 somewhere is kind of weird.

    UUID v4 = random, but with a 4 in the version hex char…
    xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx

    … With that one tiny change, Quasar produces valid UUIDs. Seems like a decent request to me.



  • @crazymind for what it’s worth, this is all you have to do to convert the Quasar UID to a UUID v4:

    function uuid () {
    let uuid = uid()
    return uuid.substr(0, 14) + ‘4’ + uuid.substr(15)
    }

    While Quasar uid() uses Math.random() for speed, and for which a very feeble case for “but it’s not technically cryptographic quality” can be made, that argument simply cannot be made for avoiding collisions as Math.random() indeed is an excellent source of entropy which is all UUID v4 promises.

    You can feel confident that simply adding the 4 makes it UUID compatible, it will pass all UUID validators, and your UUIDs can play in the global UUID space properly without collisions.

    Since Quasar Framework has gone through effort to mimic a UUID look and feel, I think it may have been developed either before UUID v4, or was kept non-standard because weird math Nazis like to chastise Math.random(), much to the detriment of the entire universe. I bet my life that this will serve you just find if you run on standard browsers and don’t let anyone hijack Math.random() with something stupid in your code.


Log in to reply