Generating a random number

Would something like this do the trick?

random = Array.new(6){rand(6)}.join

Regards,
Eric

What I did:

  def self.generate_invoice_id
    record = Object.new
    while record
      random = rand(999999999)
      record = find(:first, :conditions => ["invoice_id = ?", random])
    end
    return random
  end

Put that in the model and I get a random invoice number when I need
it..

How about something like:

"%09d" % rand(1000000000)

Or... this way seems even better:

Array.new(9){rand 10}.join

Where 9 can be replaced by however many digits you want.

-Dimo
http://strd6.com/blog

Thanks everyone for your help. A couple different ways actually worked
that you all suggested.

That was just driving me crazy not being able to figure out the small
details of a random number in Rails. Every language does it slightly
differently too.

Thanks,

Justin