GUIDs in a C++ Linux GCC app

吃可爱长大的小学妹 提交于 2020-01-01 09:45:38

问题


I've got a bunch of servers running this Linux app. I'd like for them to be able to generate a GUID with a low probability of collision. I'm sure I could just pull 128 bytes out of /dev/urandom and that would probably be fine, but is there a simple & easy way to generate a GUID that is more equivalent to the Win32 one? Specifically, one that takes into account space (well, MAC address), time, and randomness? I don't want to call off the box for it, I just want something like CreateGuid()


回答1:


This Internet Draft describes one type of UUID in great details and I have used a similar approach with great success when I needed a UUID implementation and could not link to an existing library for architectural reasons.

This article provides a good overview.




回答2:


There is libuuid.




回答3:


If you are going to use something then an Internet standard would be a good idea:
Check out RFC (Request For Comment).

The one I know that is specific to GUID is: RFC 4122




回答4:


There is a Boost version available.

http://www.boostpro.com/vault/index.php?action=downloadfile&filename=uuid_v11.zip&directory=&PHPSESSID=69e18b945f686398b963710fd52f143a



来源:https://stackoverflow.com/questions/153676/guids-in-a-c-linux-gcc-app

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!