コード例 #1
0
        /*
         * @param min: borne inférieure de la génération
         * @param max: borne supérieure de la génération
         * @return un réel positif aléatoire à 5 décimales entre min et max
         * */
        public static double Next(int min, int max)
        {
            if (min < 0 || max < min)
            {
                throw new ArgumentException("Parametres incorrectes");
            }
            double dec   = r.NextDouble();
            double value = RandomInt.Next(min, max - 1) + dec;

            return(Math.Round(value, 5, MidpointRounding.AwayFromZero));
        }
コード例 #2
0
        /*
         * @param length: number of digits wanted
         * @return a positive integer of 'length' digits
         * */
        public static double Next(int length)
        {
            int    i;
            double res = 0;

            for (i = length - 1; i >= 0; i--)
            {
                res = res + RandomInt.Next(0, 9) * Math.Pow(10, i);
            }
            return(res);
        }
コード例 #3
0
        /*
         * @param length: length of the string you want to get
         * @return a alphanumerical string of 'length' characters
         * */
        public static string Next(int length)
        {
            int    i = length;
            string s = "";

            while (i-- > 0)
            {
                int r = RandomInt.Next(0, 61);
                s = s + array[r];
            }
            return(s);
        }
コード例 #4
0
        /*@param l: the List<T> the user wants to shuffle*/
        public static List <T> Shuffle <T>(IList <T> l)
        {
            List <T> list = new List <T>(l);
            int      size = l.Count;

            while (size-- > 1)
            {
                int index = RandomInt.Next(0, size);
                T   value = list[index];
                list[index] = list[size];
                list[size]  = value;
            }
            return(list);
        }
コード例 #5
0
 /*
  * @return: un réel positif aléatoire à 5 décimales
  * */
 public static double Next()
 {
     return(RandomInt.Next() + r.NextDouble());
 }
コード例 #6
0
        public static T GetRandom <T>(IList <T> l)
        {
            int n = RandomInt.Next(0, l.Count - 1);

            return(l[n]);
        }