Could this cause multiple identical GUIDs?

自作多情 提交于 2019-12-01 15:08:29

问题


As GUID generation is time-dependent, if System.Guid.NewGuid() is called multiple times at the exact same instant on different threads, could it return identical GUIDs?


回答1:


On Windows, GUIDs (UUIDs) are created from a cryptographic random number generator with UuidCreate. They are version 4 UUIDs in terms of RFC 4122. No timestamps or ethernet cards are involved, unless you're using old school version 1 GUIDs created with UuidCreateSequential.

See also How Random is System.Guid.NewGuid()? (Take two)




回答2:


No, there is a serial number inside it that changes for each call, so multiple simultaneous calls on different threads on the same system will not create duplicate Guids.

That does not mean that there is a visible part of the Guid that you can see increments for each call.




回答3:


The Transact-SQL NEWID function and the application API functions and methods generate new uniqueidentifier values from the identification number of their network card plus a unique number from the CPU clock. Each network card has a unique identification number. The uniqueidentifier value that is returned by NEWID is generated by using the network card on the server. The uniqueidentifier value returned by application API functions and methods is generated by using the network card on the client.

.It wont generate duplicates in time or in any pc as per msdn.




回答4:


Unless your threads are running on different cores on your machine, only one thread will be actually running at a given time. Hence, I do not think it is very likely that calls to NewGuid() will take place at the exact same time.



来源:https://stackoverflow.com/questions/3004151/could-this-cause-multiple-identical-guids

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