12.02.2016, 12:26
Quote:
That won't be unique. That code will only have 1040 possible outcomes (2 * 26 * 2 * 10), which isn't a lot.
|
Assuming that
Код:
SALT[SALT_LENGTH] = ( random(2) ? (random(26) + 'A') : (random(10) + '0') );
http://www.wolframalpha.com/input/?i...r+i%3D1+to+n-1
So your UUID has 1458599936 possible combinations. As much as it looks like, it isn't. I'd recommend you increase the length from 6 to something between 20 and 24 in order to always generate really unique UID's.
Here's an improved (and fixed; you forgot null termination on strings) version:
Код:
GenerateUuid() { static const rand_len = 22; static const prefix[] = "LRP"; new uuid[sizeof(prefix) + rand_len] = prefix; new rand_str[rand_len + 1]; for (new i; i != rand_len; i++) { uuid[i + sizeof(prefix) - 1] = random(2) ? (random(26) + 'A') : (random(10) + '0'); } return uuid; }