| 39 | } |
| 40 | // Version 1 (Time-Based) UUID |
| 41 | function UUIDv1(time) { |
| 42 | return [ |
| 43 | hex((time & 0xf) << 24, 1).substring(0, 1) + |
| 44 | hex(Math.random() * 0xfffffff, 7), // add random number since we don't have 100-nanosecond precision |
| 45 | hex((time & 0xffff0) >> 4, 4), |
| 46 | "1" + hex(time & (0xfff00000 >> 20), 3), |
| 47 | hex(Math.random() * 0x3fff | 0x8000, 4), |
| 48 | Net.get('MAC')?.split(':').join('') ?? |
| 49 | hex((Math.random() * 0xffffffff) | 0x02000000, 8) + |
| 50 | hex(Math.random() * 0xffff, 4), |
| 51 | ] |
| 52 | .join('-') |
| 53 | .toUpperCase(); |
| 54 | } |
| 55 | |
| 56 | // Version 4 (Random) UUID |
| 57 | function UUIDv4() { |