Comment detail

重複無し乱数 (Nested Flatten)
普通にやってみた
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
def bingo(num)
        raise ArgumentError.new("fixnum only") unless num.kind_of? Fixnum
        raise ArgumentError.new("1 ijyou de onegai simasu") unless num >= 1

        results = []

        ary=(1..num).to_a
        ary.size.times{
                index = (rand * ary.size).to_i
                results << ary.delete_at(index)
        }

        results
end

Index

Feed

Other

Link

Pathtraq

loading...