[#1263] Draft of the updated Ruby FAQ — Dave Thomas <Dave@...>

33 messages 2000/02/08

[#1376] Re: Scripting versus programming — Andrew Hunt <andy@...>

Conrad writes:

13 messages 2000/02/15

[#1508] Ruby/GTK and the mainloop — Ian Main <imain@...>

17 messages 2000/02/19
[#1544] Re: Ruby/GTK and the mainloop — Yasushi Shoji <yashi@...> 2000/02/23

Hello Ian,

[#1550] Re: Ruby/GTK and the mainloop — Ian Main <imain@...> 2000/02/23

On Wed, Feb 23, 2000 at 02:56:10AM -0500, Yasushi Shoji wrote:

[#1516] Ruby: PLEASE use comp.lang.misc for all Ruby programming/technical questions/discussions!!!! — "Conrad Schneiker" <schneiker@...>

((FYI: This was sent to the Ruby mail list.))

10 messages 2000/02/19

[#1569] Re: Ruby: constructors, new and initialise — Yukihiro Matsumoto <matz@...>

The following message is a courtesy copy of an article

12 messages 2000/02/25

[ruby-talk:01218] Trivial FAQ bug

From: Dave Thomas <Dave@...>
Date: 2000-02-02 04:01:35 UTC
List: ruby-talk #1218
I wasn't sure from the intro page who is maintaining the FAQ, but I
came across a slightly subtle bug in an example:


   7.3 How can I choose 5 different numbers between 0 and 51 randomly? 

   Next method returns an array containing m randomly chosen numbers
   between 0 and n.

         def sample(n, m)
           if m.zero?
             []
           else
             s = sample(n-1, m-1)
             t = rand(n+1)
             s.concat s.include?(t) ? n : t
           end
         end

   To write it in non-recursive iterated form, 

         def sample(n, m)
           s = []
           ((n-m)...n).each do |j|
             t = rand(j+2)
             s.concat s.include?(t) ? j+1 : t
           end
           s
         end

The code fragments don't compile - concat should be '<<' or push.

Also, I think second sample also does not generate a uniform
distribution of numbers. The first time around the loop, it generates
numbers between 0 and (n-m)+2, the next time from (n-m)+3 and so on. I 
_think_ this means that the results will tend to be skewed towards the 
low side.


In general, would anyone be interested in Andy and I taking the
English FAQ and updating it? We'd be more than happy to.


Regards

Dave


In This Thread

Prev Next