开发者

What is the best way to generate unique session IDs?

开发者 https://www.devze.com 2022-12-13 12:15 出处:网络
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?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消