I want to generate a 16 character alphanumeric Session ID string. What is the best way to do this so that it is gua开发者_高级运维ranteed that the string generated will be unique every time?
Note: I will be using C++ to generate the session IDs.
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?
Use a GUID. How you generate one will depend on the platform you're running on.
精彩评论