示例#1
0
        private int FindFirstRepeatedNumber(int n)
        {
            int           count = 0;
            HashSet <int> set   = new HashSet <int>();

            while (true)
            {
                int randomNumber = StdRandom.uniform(n);
                if (set.Contains(randomNumber))
                {
                    return(count);
                }
                else
                {
                    set.Add(randomNumber);
                    count++;
                }
            }
        }
示例#2
0
        public int findCountBeforeAllPossibleIntegersHasBeenGenerated(int n)
        {
            int count = 0;
            Dictionary <int, int> dictionary = new Dictionary <int, int>();
            HashSet <int>         set        = new HashSet <int>();
            bool everyThingGenerated         = false;

            while (!everyThingGenerated)
            {
                int randomNumber = StdRandom.uniform(n);
                if (!set.Contains(randomNumber))
                {
                    set.Add(randomNumber);
                }
                count++;
                if (set.Count == n)
                {
                    everyThingGenerated = true;
                }
            }

            return(count);
        }