Creating UUIDs with JavaScript in Node & Browsers

preview_player
Показать описание
This video tutorial explains how to use the built-in JavaScript crypto modules in both NodeJS and in all browsers to generate UUIDs and GUIDs.

Рекомендации по теме
Комментарии
Автор

Thank you for the quality video. I love understanding how things work, and how you continue to explain them.

ofeenee
Автор

Thanks for walking through this topic. I have a feeling once you start using this, it introduces a whole new group of options to manage resources more easily.

colbr
Автор

Always quality content from you bro, thank you

dev_ression
Автор

Do you think that the XOR step really introduces additional randomness, or is it just a clever step in a clever algorithm to generate the UUID? Intuitively, if the random number generator is generating random numbers with somewhat equal distribution over the range 0-255, then flipping arbitrary bits doesn't seem like it would really change the randomness.

It looks like the only time the random value generated by getRandomValues() is altered by the XOR operation is for the positions where the character value is 1. For character value 0, the XOR simply passes the random number through as is (effectively equivalent to OR-ing them with the 0). For character value 8, the random value has already been lopped down to its 2 least significant bits, so XOR-ing with 8 also just passes those LSBs as is onto the 8 (again, effectively equivalent to OR-ing them with the 8). So the XOR doesn't _really_ do a whole lot to change the values generated by getRandomValues().

Here's why I think it's a clever coding trick: Aside from the 8-4-4-4-12 groupings/pattern for the UUID, it looks like there are 2 restrictions on characters in specific locations. 1) In group 3, the first character must be a "4"; and 2) in group 4, the first character must have the bit pattern "10xx", where xx is randomly generated. I think that the XOR operation is there as a way to code restriction #2. (You couldn't use a plain OR operation, as that would cause bit 0 to always be set for positions with character value 1.)

mykalimba
Автор

Thank you! Are you planning to make videos about NodeJS streams?

aleksandr
Автор

I’m still struggling to wrap my head around the line with the bitwise operators.

ofeenee
Автор

what if the same string comes again, what are the chances,

GL-iejq
Автор

but you cannot use it in map() as a key, because it gives the same id for all Link elements.

Hicham-zt
Автор

node has both its own generateUUID with and the browser's generateUUID with

soniablanche