From: Robert Dober Date: 2008-04-11T20:56:45+09:00 Subject: Re: how to create random object to a particular ruby object ? On Fri, Apr 11, 2008 at 1:16 PM, Robert Klemme wrote: > 2008/4/11, Pokkai Dokkai : > > > how to create random object to a particular ruby object ? > > > > for example i want like this > > You need more input parameters: > > > rand(Fixnum) --> 345 (randomly) > Number range? > > > > rand(Float) --> 3877.5545(randomly) > Number range? > > > rand(String) --> "sfskgksf" (randomly) > Length of String? Chars allowed in String? > > > rand(boolean) --> 0(randomly) > That's easy > rand(2) == 0 I am surprised that you are so permissive Robert ;). I would say [true,false][rand(2)] or even, just to have some fun [false,nil][rand(2)].send([:&&,:||][rand(2)], method_returning_a_completeley_random_object) to reflect Ruby's what's "true" and what's "false" semantics. Cheers Robert > -- > use.inject do |as, often| as.you_can - without end -- http://ruby-smalltalk.blogspot.com/ --- Whereof one cannot speak, thereof one must be silent. Ludwig Wittgenstein