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); }
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))); }
public RandomWordChooser(ITrigramStatistics stats, Random random) { _random = random; _stats = stats; }