class PasswordGenerator def initialize(len=8,caps=true,digits=false) @length = len @caps = caps @digits = digits @onecon = ['b','c','d','f','g','h','j','k','l','m','n','p','r','s','t','v','w','x','z'] @onevow = ['a','e','i','o','u'] @onevow = [@onevow,@onevow].flatten @twovow = ['ee','oo','ai','ea','ia'] @starttwocon = ['sh','ch','pr','tr','th','qu'] @endtwocon = ['sh','ch','rt','rp','th','ss','tt','lz','ts','gs','gz','tz','gh','nd','ld','wd'] @allstart = [@onecon,@onevow,@starttwocon,'y'].flatten @allend = [@onecon,@onevow,@endtwocon,'y'].flatten @allone = [@onecon,@onevow,'y'].flatten @alltwo = [@twovow,@starttwocon,@endtwocon].flatten @allcon = [@onecon,@starttwocon,@endtwocon,'y'].flatten @allvow = [@onevow,@twovow].flatten end def generatePassword pass = '' start = true while pass.length < (@length - 2) do if start pass = randElement(@allstart) i = (@onevow.include?(pass[-1,1]) ? 0 : 1) start = false end i += 1 if (i % 2) == 0 # add vow next pass += randElement(@allvow) else # add con next pass += randElement(@allcon) end if rand(3) == 2 && @digits pass += rand(10).to_s start = true end end while pass.length < @length i += 1 if (i % 2) == 0 pass += randElement(@onevow) else if pass.length == (@length - 1) pass += randElement(@onecon) else temp = [@onecon,@endtwocon].flatten pass += randElement(temp) end end end pass end private def randElement(sounds) sound = sounds[rand(sounds.size)] return sound.upcase if @caps && rand(3) == 0 return sound end end passgen = PasswordGenerator.new(8,true,true) 20.times { print(passgen.generatePassword+' ') } print("\n")