1

There is uuid but it's 32 chars long (36 if i include dash) but the requirement in my case is 30 chars long.

Is there any alternative for uuid?

Tuan Anh Tran
  • 6,807
  • 6
  • 37
  • 54

1 Answers1

0

You can use the plain bytes (16 bytes) and encode them using Base64 instead of hex (base 16). The result will be 24 bytes long.

Maybe this answer will help you: Javascript convert GUID in string format into Base64

Community
  • 1
  • 1
Sebastian S
  • 4,420
  • 4
  • 34
  • 63
  • how unique would that be compare with substring uuid down to 30 chars long? – Tuan Anh Tran Oct 15 '15 at 10:10
  • @TuanAnhTran if you substring from 32 chars (no dashes) to 30 chars, 2 hex chars are missing. 2 hex chars are 1 byte. So you have 120 instead of 128 bits. Keeping the birthday paradox in mind you will have a collision probability of 50% after generating 2^60 IDs instead of 2^64. – Sebastian S Oct 15 '15 at 10:20