[Rails] Re: Generating a random number

2008-10-28 Thread command0
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 On Oct 17, 1:02 pm, Daniel M

[Rails] Re: Generating a random number

2008-10-17 Thread Daniel Moore
How about something like: "%09d" % rand(10) 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 --~--~-~--~~~---~--~~ You received this message because you are

[Rails] Re: Generating a random number

2008-10-16 Thread Freddy Andersen
What I did: def self.generate_invoice_id record = Object.new while record random = rand(9) 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.. --~--

[Rails] Re: Generating a random number

2008-10-16 Thread emarthinsen
Would something like this do the trick? random = Array.new(6){rand(6)}.join Regards, Eric --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails

[Rails] Re: Generating a random number

2008-10-16 Thread Philip Hallstrom
On Oct 16, 2008, at 4:38 PM, command0 wrote: > > Hey guys, > > Ok, so right now I am working on generating a random number with ruby > or rails? > > So far I have gathered that I somehow or another want to use the > rand() helper to so, but not sure how to do it to achieve what I am > trying to