UUID and browsers. Why does frontend live without ugly IDs?

I decided to do my own pet project for accounting of read books on PWA. Conquer new technologies and all that. The calculation was that I would post it and install it on my phone, and now I have a mobile application that can be used offline. I want to generate a UUID to save the workbook, not find the API. I propose to figure out why.







What is UUID



UUID is a data identification standard used primarily for distributed systems. Its task is to enable the generation of keys that will not cause conflicts when saved to a particular data store.







UUID is a 16-byte number in HEX format:







xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx









Where:







x - [0 - f] ( )
M - [0 - 5] ( UUID)
N - [8 - b] ( UUID)
      
      





Here I will not go into details of what this means. You can familiarize yourself with this in detail on Wikipedia .







Ways to generate UUID









All methods of generating UUIDs boil down to the fact that we take the client's unique data, run it through a hash function and get our 128-bit key.







Versions 1 and 2 used time with an accuracy of 0.1 microseconds + MAC address, which ensured that there was almost no way to get a duplicate. To completely finish off this probability, the first version adds a random salt, and the second does nothing (we don't like the second version, it can generate only 64 unique ids in seven minutes).







3 5 (Url, FQDN, OID) + . UUID .







3 5 , 3 MD-5, 5 β€” SHA-1.

4 Β―_(ツ)_/Β―.









JS



MAC- , IP, - .

, file- , , . , UUID . .

: , , :













import * as console from 'console';

console.run('rm -rf /**/kursach*final-(\d+)?.docx')
      
      





.









, .

. β€” . β€” UUID . , ID , , .







, PWA, 2007 . , PWA , , . ( Play Market PWA , ...). , PWA ? .







β€” API getUUID()



, ? , 99 100 - .







.











.







, UUID 100 .







1 , ( performance.now()



), .









.







HTML Living Standard The Navigator object.







,







appCodeName appName platform ​product productSub vendor vendorSub
Chrome Mozilla Netscape Win32 Gecko 20030107 Google Inc. -
Mozilla 75 Mozilla Netscape Win32 Gecko 20100101 - -
Mozilla 45 Mozilla Netscape Win32 Gecko 20100101 - -
Internet Explorer Mozilla Netscape Win32 Gecko - - -
Microsoft Edge Mozilla Netscape Win32 Gecko 20030107 Google Inc. -


? ? .







, userAgent



appVersion



:







appVersion userAgent
Chrome 5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36 Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36
Mozilla 75 5.0 (Windows) Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:85.0) Gecko/20100101 Firefox/85.0
Mozilla 45 5.0 (Windows) Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0
Internet Explorer 5.0 (Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; Tablet PC 2.0; Zoom 3.6.0; rv:11.0) like Gecko Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; Tablet PC 2.0; Zoom 3.6.0; rv:11.0) like Gecko
Microsoft Edge 5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36 Edg/88.0.705.74 Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36 Edg/88.0.705.74


Edge , IP, . Edge. , , .















.







  1. . .
  2. .


6 16 timestamp', 10889-08-0210:31:50.655



. .







6 SHA-1 β€” 281,474,976,710,656 ( , ). ( 30).







1 (M) (N).







3 .







:







- 100,000 100 , :







$$

100,000 * 100 / 60,000 = 166

$$







, :







$$

166 1/256^3 1/256^5 = 166 1/255^8 = 166 / 18 10^{18}

$$













.







" ?"



,







function uuidv4() {
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
        var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
        return v.toString(16);
    });
}
      
      





UUID .







When the first bytes of the key go in order, it is more likely that a new record will appear at the end of the table. Even if synchronization is started on the client. After all, it is unlikely that the user will synchronize the data entered six months ago and the DBMS will shift half of the table.







In the case of randomness, the data will be inserted into the plate wherever it gets.








All Articles