Skip to content

Instantly share code, notes, and snippets.

@stevenpetryk
Last active September 25, 2015 13:50
Show Gist options
  • Save stevenpetryk/67e16099c40a979c3060 to your computer and use it in GitHub Desktop.
Save stevenpetryk/67e16099c40a979c3060 to your computer and use it in GitHub Desktop.
MAX_RUNS = 100
MAX_STATES = 500
MAX_ALPHABET_SIZE = 10
def get_random_dfa
lines = []
states = (0..(1 + rand(MAX_STATES - 1))).to_a
alphabet_size = 1 + rand([MAX_ALPHABET_SIZE, states.count].min - 1)
accept_states = states.sample(1 + rand(states.count - 1))
lines << "#{states.count} #{alphabet_size}"
lines << "#{accept_states.count} #{accept_states.join(' ')}"
states.count.times do |n|
lines << (0...alphabet_size).map do |letter|
states[letter * rand(5) % states.count]
end.join(' ')
end
lines.join("\n")
end
puts MAX_RUNS
MAX_RUNS.times do
puts get_random_dfa
puts
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment