Tuesday, February 28, 2012

Re: [Rails] ensuring random list of numbers are unique

> 500.times.map { Integer((rand * 1) * 1000) / Float(1000) }
>
> Basically, this gives me a list of 500 random decimal numbers that are
> rounded to 3 places. However, I also want to make sure that all are
> unique.

Tack a .uniq to the end...

http://ruby-doc.org/core-1.9.3/Array.html#method-i-uniq

-philip

--
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-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate