Created
August 26, 2013 01:32
-
-
Save PaulStovell/6337411 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static async Task<Guid> NewReallyRandomGuid() | |
{ | |
// Got this value from the 'Create GUID' dialog in Visual | |
// Studio. Guaranteed to be unique. | |
var guid = Guid.Parse("43BB5AE8-653E-4985-88F8-A8C4A92C9BD5").ToByteArray(); | |
//Prevent collisions by XORing with random data | |
byte[] bytes = new byte[16]; | |
var rng = new RNGCryptoServiceProvider(); | |
rng.GetBytes(bytes); | |
for(int i = 0; i < guid.Length; i++) | |
{ | |
guid[i] = (byte) (guid[i] ^ bytes[i]); | |
} | |
return new Guid(guid); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment