CFGLib.GrammarGenerator.RandomProduction C# (CSharp) Method

RandomProduction() public method

public RandomProduction ( int maxProductionLength, int numNonterminals, IList terminals, bool useNull = true ) : Production
maxProductionLength int
numNonterminals int
terminals IList
useNull bool
return Production
		public Production RandomProduction(int maxProductionLength, int numNonterminals, IList<Terminal> terminals, bool useNull = true) {
			var lhs = RandomNonterminal(numNonterminals);
			var weight = 100 * _rand.NextDouble() + 1.0;
			var productionLength = useNull ? _rand.Next(maxProductionLength + 1) + 0: _rand.Next(maxProductionLength + 0) + 1;
			Sentence rhs = new Sentence();
			for (int i = 0; i < productionLength; i++) {
				if (_rand.Next(2) == 0) {
					rhs.Add(RandomNonterminal(numNonterminals));
				} else {
					rhs.Add(RandomTerminal(terminals));
				}
			}

			return new Production(lhs, rhs, weight);
		}