Created
August 1, 2016 15:31
-
-
Save jameshulse/f5b85ca038c729a9b772c20390f0d5bc 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 class DeterministicGrouping | |
{ | |
public static bool IsSelected(Guid entropy, ulong numerator, ulong denominator = 100) | |
{ | |
if(numerator > denominator) | |
throw new ArgumentOutOfRangeException(nameof(numerator), "The numerator cannot be larger than the denominator."); | |
if (numerator <= 0) | |
throw new ArgumentOutOfRangeException(nameof(numerator), "The numerator must be a positive non-zero value."); | |
if (denominator <= 0) | |
throw new ArgumentOutOfRangeException(nameof(denominator), "The denominator must be a positive non-zero value."); | |
ulong guidNumericValue = BitConverter.ToUInt32(entropy.ToByteArray().Take(4).ToArray(), 0); | |
return guidNumericValue%denominator < numerator; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment