コード例 #1
0
        /// <summary>
        /// Gives back a randomly chosen quote from the given list
        /// </summary>
        private string GetQuote(ref BindingList <Quote> quoteList, string defaultQuote)
        {
            if (quoteList.Count == 0)
            {
                return(defaultQuote);
            }
            else if (quoteList.Count == 1)
            {
                if (quoteList[0].IsActive)
                {
                    return(quoteList[0].QuoteText);
                }
                else
                {
                    return(defaultQuote);
                }
            }
            else
            {
                int quoteIndex;

                do
                {
                    quoteIndex = rand.GetRandInt(0, quoteList.Count - 1);
                } while (!quoteList[quoteIndex].IsActive);

                return(quoteList[quoteIndex].QuoteText);
            }
        }
コード例 #2
0
        private void TestRandInt(ref RandIntMem randIntMem, int amountToRemember)
        {
            List <int> generatedNums   = new List <int>();
            bool       isThereNoRepeat = false;

            for (int i = 0; i < amountToRemember; ++i)
            {
                int num = randIntMem.GetRandInt(0, amountToRemember);

                if (generatedNums.Contains(num))
                {
                    isThereNoRepeat = false;
                    break;
                }
                else
                {
                    generatedNums.Add(num);
                    isThereNoRepeat = true;
                }
            }


            Assert.IsTrue(isThereNoRepeat);
        }