Created
December 13, 2014 04:52
-
-
Save DataKinds/b70cfbd98e0eda9ff7ca to your computer and use it in GitHub Desktop.
Random BF Generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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