Friday, September 18, 2009

Fixed Length Random numbers Ruby On Rails

Generating Random numbers in Ruby On Rails is very easy even without gems.

If u want 6 Digit random number try bellow code.
rand(999999).to_s.center(6, rand(9).to_s)

If you want 5 digit try bellow
rand(99999).to_s.center(5, rand(9).to_s)

Like this we can generate any number of digits random number..

No comments:

Post a Comment