Last active
August 24, 2016 11:18
-
-
Save zhenlinyang/514578fa4fd4065775ee5ae2967ebe1d to your computer and use it in GitHub Desktop.
Get No-repeat Random Value
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 RandomMng | |
{ | |
private static Random random = new Random(); | |
public static int GetRandomInt32(ICollection<int> coll) | |
{ | |
int ret; | |
do | |
{ | |
ret = random.Next(); | |
} while (coll.Contains(ret)); | |
return ret; | |
} | |
public static ulong GetRandomUInt64(ICollection<ulong> coll) | |
{ | |
ulong ret; | |
do | |
{ | |
var num = new byte[8]; | |
random.NextBytes(num); | |
ret = BitConverter.ToUInt64(num, 0); | |
} while (coll.Contains(ret)); | |
return ret; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment