Exemplo n.º 1
0
        // random select m numbers from total
        public static List <int> RandomSelect(int m, int total)
        {
            byte[] seed  = BytesHelper.GenRandomBytes(256);
            var    cache = new List <KeyValuePair <int, int> >();

            for (int i = 0; i < total; i++)
            {
                //int hash = BitConverter.ToInt32(Sha256(BitConverter.GetBytes(i + 1).Concat(seed)), 0);

                int hash = BitConverter.ToInt32(seed, i % 224) ^ (i + 1);
                cache.Add(new KeyValuePair <int, int>(i + 1, hash));
            }

            return(cache.OrderBy(p => p.Value).Take(m).Select(p => p.Key).ToList());
        }