Esempio n. 1
0
        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, 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);
            Generate(builder, transition.To);
        }
Esempio n. 2
0
        private void AppendChoice(StringBuilder builder, Transition transition)
        {
            var c = (char)Xeger.GetRandomInt(transition.Min, transition.Max, random);

            builder.Append(c);
        }