24.02.2016, 02:29
Quote:
You're calculating it wrong.
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; } |
You also dont need that long IDs then, which saves generation time and hdd/ram space. You should aim for a good balance between the absolute maximum of different IDs and the time it needs to check for duplicates. Just like good code should aim for 100% reliability, not just for 99,99999999%.