Skip to content

Instantly share code, notes, and snippets.

@kmarsh
Created April 23, 2009 21:44
Show Gist options
  • Save kmarsh/100782 to your computer and use it in GitHub Desktop.
Save kmarsh/100782 to your computer and use it in GitHub Desktop.
def generate_code
generated_code = nil
loop do
srand(Time.now.to_f)
chars = ("A".."Z").to_a + ("2".."9").to_a
generated_code = ""
1.upto(5) { |i| generated_code << chars[rand(chars.size - 1)] }
break if Lead.count(:conditions => {:code => generated_code}) == 0
end
update_attribute(:code, generated_code)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment