private void Generate(StringBuilder builder, State state) { var transitions = state.GetSortedTransitions(true); if (transitions.Count == 0) { if (!state.Accept) { throw new InvalidOperationException("state"); } return; } int nroptions = state.Accept ? transitions.Count : transitions.Count - 1; int option = Xeger.GetRandomInt(0, nroptions, this.random); if (state.Accept && option == 0) { // 0 is considered stop. return; } // Moving on to next transition. Transition transition = transitions[option - (state.Accept ? 1 : 0)]; this.AppendChoice(builder, transition); this.Generate(builder, transition.To); }
private void AppendChoice(StringBuilder builder, Transition transition) { var c = (char)Xeger.GetRandomInt(transition.Min, transition.Max, this.random); builder.Append(c); }