Question

I want to generate a 16 character alphanumeric Session ID string. What is the best way to do this so that it is guaranteed that the string generated will be unique every time?

Note: I will be using C++ to generate the session IDs.

Was it helpful?

Solution

Typically you would create a GUID using whatever language/OS services provide such a service. Commonly available GUIDs are 16 bytes long, which in hex representation would be 32 characters. You can base64 encode that and get it slightly smaller (22 characters or so). Do you really need exactly 16 characters?

OTHER TIPS

Use a GUID. How you generate one will depend on the platform you're running on.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top