module Algorithm::Genetic::Mutation::Shift
Public Instance Methods
mutate(code)
click to toggle source
# File lib/algorithm/genetic/mutation/shift.rb, line 4 def mutate(code) index = (rand * code.length).to_i direction = rand <= 0.5 ? -1 : 1 begin new_char = (code[index].ord + direction).chr rescue return(code) end code[index] = new_char return code end