コード例 #1
0
        private char GetNextRandomCharacter(List <RandomCharacterProvider> providers)
        {
            RandomCharacterProvider randomProvider = GetRandomProvider(providers);
            char result = randomProvider.GetNextRandomChar();

            return(result);
        }
コード例 #2
0
        private RandomCharacterProvider GetRandomProvider(List <RandomCharacterProvider> providers)
        {
            List <int> providerCharacterCounts = providers.Select(prvd => prvd.Chracters.Length).ToList();
            int        allChractersCount       = providerCharacterCounts.Sum();

            int randomChracterIndex = Rand.Next(0, allChractersCount);

            int randomProviderIndex = -1;
            int charactersCountSum  = 0;

            do
            {
                randomProviderIndex++;
                charactersCountSum += providerCharacterCounts[randomProviderIndex];
            } while (charactersCountSum < randomChracterIndex);

            RandomCharacterProvider randomProvider = providers[randomProviderIndex];

            return(randomProvider);
        }