swa66 - 11:07 am on Mar 10, 2013 (gmt 0)
Doing the +1 for every hit requires you to
- mutex lock
- read the stored value
- increment the value
- write the new value to storage
unless I'd need 100% sure unique numbers, I'd go for a large random value instead. It's much more efficient and doesn't need any locking nor storage.
128bit random would give you 2^64 tries on average to find a collision (birthday paradox) - for most uses that's more than good enough.
For your use it would be more than enough.
Base64 encoding of the random value makes it safe and relatively compact to transport it.
Actually since it's not cryptographic, you could just use the md5 or sha-1 value of a string composed of the time of day, date, browser string, referrer, some small random value, the IP address, the port number, ... (anything that changes actually)
that would be more than good enough too.