Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 10th, 2012  |  syntax: None  |  size: 0.29 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # Random is available in 1.9 (or 1.8 w/backports)
  2.  
  3. def random_routing_number
  4.   digits = Random.new.rand(10_000_000..99_999_999).to_s.split('')
  5.  
  6.   sum = digits.each_slice(3).inject(0) do |sum, (d1, d2, d3)|
  7.     sum + 7 * d1.to_i + 3 * d2.to_i + 9 * d3.to_i
  8.   end
  9.  
  10.   digits.push(sum % 10).join
  11. end