コード例 #1
0
        /// <summary>
        /// Just shows how this class can be used; samples n elements from and int[] array.
        /// </summary>
        /// <param name="n"></param>
        /// <param name="elements"></param>
        /// <returns></returns>
        public static int[] SampleArray(int n, int[] elements)
        {
            RandomSamplingAssistant assistant = new RandomSamplingAssistant(n, elements.Length, null);

            int[] sample = new int[n];
            int   j      = 0;
            int   Length = elements.Length;

            for (int i = 0; i < Length; i++)
            {
                if (assistant.SampleNextElement())
                {
                    sample[j++] = elements[i];
                }
            }
            return(sample);
        }
コード例 #2
0
        /// <summary>
        /// Tests the methods of this class.
        /// To do benchmarking, comment the lines printing stuff to the console.
        /// </summary>
        /// <param name="n"></param>
        /// <param name="N"></param>
        public static void Test(long n, long N)
        {
            RandomSamplingAssistant assistant = new RandomSamplingAssistant(n, N, null);

            List <long> sample = new List <long>((int)n);
            DateTime    begin  = DateTime.Now;

            for (long i = 0; i < N; i++)
            {
                if (assistant.SampleNextElement())
                {
                    sample.Add(i);
                }
            }

            DateTime end  = DateTime.Now;
            var      diff = end.Subtract(begin).TotalMilliseconds;

            Console.WriteLine(diff);
            Console.WriteLine("sample=" + sample);
            Console.WriteLine("Good bye.\n");
        }