Skip to content

Instantly share code, notes, and snippets.

@logicrime
Created September 8, 2015 03:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save logicrime/e5ee564f2615602d2f61 to your computer and use it in GitHub Desktop.
Save logicrime/e5ee564f2615602d2f61 to your computer and use it in GitHub Desktop.
generates random string to match another random string or How I learned to write code yet not do any work
#!/usr/bin/env ruby
class Cry
def initialize(pool)
@data = pool.split("")
end
def take(num)
res = ""
num.times do
res.concat(@data.sample)
end
return res
end
end
def bogo(length,interval=500)
c = Cry.new("0123456789abcdefghijklmnopqrstuvwxyz")
d = Cry.new("0123456789abcdefghijklmnopqrstuvwxyz")
tries = 0
match = c.take(length)
while (d.take(length) != match) do
tries+=(1)
if tries.modulo(interval) == 0 then puts (tries / interval) end
end
end
bogo(10,1000000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment