Ruby 1.9.0 リファレンスマニュアル > ライブラリ一覧 > library _builtin > class Array > choice

instance method Array#choice

choice -> object

配列の要素を1個ランダムに選んで返します。

srand()が有効です。

例:

a = (1..10).to_a
p a.choice        #=>  9
p a.choice        #=> 10
p a               #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]