Skip to content

Instantly share code, notes, and snippets.

@DataKinds
Created December 13, 2014 04:52
Show Gist options
  • Save DataKinds/b70cfbd98e0eda9ff7ca to your computer and use it in GitHub Desktop.
Save DataKinds/b70cfbd98e0eda9ff7ca to your computer and use it in GitHub Desktop.
Random BF Generator
def genBF(seed, length)
prng = Random.new(seed)
program = ""
loopDepth = 0
length.times do
ins = [?+, ?-, ?<, ?>, ?,, ?., ?+, ?-, ?<, ?>, ?,, ?., ?[, ?]].sample(random: prng)
ins = ?[ if loopDepth <= 0 and ins == ?]
loopDepth += 1 if ins == ?[
loopDepth -= 1 if ins == ?]
program += ins
end
loopDepth.times do
program += ?]
end
File.open("random.bf", "w") do |file|
file.write program
end
end
def main()
print "SEED: "
seed = gets.chomp.to_i
print "LENGTH: "
length = gets.chomp.to_i
genBF(seed, length)
end
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment