mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-04-12 12:07:05 +00:00
feat: Added method for combining GUIDs to make deterministic GUIDs
This commit is contained in:
parent
bbb09666dd
commit
f34e307a93
1 changed files with 17 additions and 0 deletions
|
|
@ -4,6 +4,9 @@ namespace ICD.Common.Utils
|
||||||
{
|
{
|
||||||
public static class GuidUtils
|
public static class GuidUtils
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Generates a pseudo-random guid from the given seed.
|
||||||
|
/// </summary>
|
||||||
public static Guid GenerateSeeded(int seed)
|
public static Guid GenerateSeeded(int seed)
|
||||||
{
|
{
|
||||||
Random seeded = new Random(seed);
|
Random seeded = new Random(seed);
|
||||||
|
|
@ -13,5 +16,19 @@ namespace ICD.Common.Utils
|
||||||
|
|
||||||
return new Guid(bytes);
|
return new Guid(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Combines the two guids to make a new, deterministic guid.
|
||||||
|
/// </summary>
|
||||||
|
public static Guid Combine(Guid a, Guid b)
|
||||||
|
{
|
||||||
|
byte[] aBytes = a.ToByteArray();
|
||||||
|
byte[] bBytes = b.ToByteArray();
|
||||||
|
|
||||||
|
for (int index = 0; index < aBytes.Length; index++)
|
||||||
|
aBytes[index] = (byte)(aBytes[index] ^ bBytes[index]);
|
||||||
|
|
||||||
|
return new Guid(aBytes);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue