Example #1
0
        /// <summary>
        /// 随机从 0 ~ max-1 中取出不重复的 num 个整数
        /// @wangzhenhai
        /// </summary>
        public static int[] GetRandom(int num, int max, MersenneTwisterRandom r)
        {
            if (num < 0 || max < 0 || num > max)
            {
                return(null);
            }

            int[] result = new int[num];
            int[] seed   = new int[max];

            for (int i = 0; i < max; i++)
            {
                seed[i] = i;
            }

            for (int i = 0; i < num; i++)
            {
                int index = r.Next(0, max - i);
                result[i]   = seed[index];
                seed[index] = seed[num - i - 1];
            }

            return(result);
        }
Example #2
0
 public RandomWeightGenerator(MersenneTwisterRandom r)
 {
     random = r;
 }
Example #3
0
 public static int MTRandom(int min, int max, MersenneTwisterRandom mtRandom)
 {
     return(mtRandom.Next(min, max));
 }