Exemplo n.º 1
0
        public static string Generate(int length, IReadOnlyCollection <ISet <char> > requiredSets, Func <string, bool> predicate, Random random, ITrigramStatistics stats)
        {
            if (length < requiredSets.Count + 2)
            {
                throw new ArgumentOutOfRangeException("length", "length cannot be less than the number of requiredSets + 2.");
            }

            string result;

            do
            {
                result = Generate(length, requiredSets, random, stats);
            }while (!predicate(result));

            return(result);
        }
Exemplo n.º 2
0
        static string Generate(int length, IReadOnlyCollection <ISet <char> > requiredSets, Random random, ITrigramStatistics stats)
        {
            var parts = new List <string>();

            var all = requiredSets.Select(s => new RandomSetChooser(s, random))
                      .Cast <IChooser <string> >()
                      .Concat(new IChooser <string>[] { new RandomWordChooser(stats, random) });

            foreach (var chooser in all)
            {
                parts.Add(chooser.GetRandom(length - GetLengthOfParts(parts)));
            }

            while (GetLengthOfParts(parts) < length)
            {
                parts.Add(random.Choose(all).GetRandom(length - GetLengthOfParts(parts)));
            }

            return(string.Concat(random.Shuffle(parts)));
        }
Exemplo n.º 3
0
 public RandomWordChooser(ITrigramStatistics stats, Random random)
 {
     _random = random;
     _stats  = stats;
 }