るりまサーチ

最速Rubyリファレンスマニュアル検索!
48件ヒット [1-48件を表示] (0.007秒)
トップページ > クエリ:sample[x] > クラス:Array[x]

別のキーワード

  1. array sample
  2. _builtin sample
  3. sample array
  4. sample random

ライブラリ

検索結果

Array#sample -> object | nil (18129.0)

配列の要素を1個(引数を指定した場合は自身の要素数を越えない範囲で n 個) ランダムに選んで返します。

..._a
p a.sample #=> 9
p a.sample #=> 10
p a.sample(3) #=> [1, 9, 3]
p a #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
//}

random SecureRandom などの乱数生成器を渡すことができます。

//emlist[例][ruby]{
require 'securerandom'
a = (1..10).to_a
p a.sample(rando...

Array#sample(n) -> Array (18129.0)

配列の要素を1個(引数を指定した場合は自身の要素数を越えない範囲で n 個) ランダムに選んで返します。

..._a
p a.sample #=> 9
p a.sample #=> 10
p a.sample(3) #=> [1, 9, 3]
p a #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
//}

random SecureRandom などの乱数生成器を渡すことができます。

//emlist[例][ruby]{
require 'securerandom'
a = (1..10).to_a
p a.sample(rando...

Array#sample(n, random: Random) -> Array (18129.0)

配列の要素を1個(引数を指定した場合は自身の要素数を越えない範囲で n 個) ランダムに選んで返します。

..._a
p a.sample #=> 9
p a.sample #=> 10
p a.sample(3) #=> [1, 9, 3]
p a #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
//}

random SecureRandom などの乱数生成器を渡すことができます。

//emlist[例][ruby]{
require 'securerandom'
a = (1..10).to_a
p a.sample(rando...

Array#sample(random: Random) -> object | nil (18129.0)

配列の要素を1個(引数を指定した場合は自身の要素数を越えない範囲で n 個) ランダムに選んで返します。

..._a
p a.sample #=> 9
p a.sample #=> 10
p a.sample(3) #=> [1, 9, 3]
p a #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
//}

random SecureRandom などの乱数生成器を渡すことができます。

//emlist[例][ruby]{
require 'securerandom'
a = (1..10).to_a
p a.sample(rando...