Created
September 8, 2015 03:16
-
-
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
This file contains 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
#!/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