るりまサーチ

最速Rubyリファレンスマニュアル検索!
99件ヒット [1-99件を表示] (0.035秒)
トップページ > クエリ:array[x] > クエリ:sample[x] > 種類:インスタンスメソッド[x]

別のキーワード

  1. array fill
  2. array []
  3. array slice
  4. array slice!

ライブラリ

クラス

モジュール

キーワード

検索結果

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

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

...した場合に発生します。

@raise ArgumentError 引数 n に負の数を指定した場合に発生します。

//emlist[例][ruby]{
a = (1..10).to_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]
//}...

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

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

...した場合に発生します。

@raise ArgumentError 引数 n に負の数を指定した場合に発生します。

//emlist[例][ruby]{
a = (1..10).to_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]
//}...

Array#sample -> object | nil (27125.0)

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

...した場合に発生します。

@raise ArgumentError 引数 n に負の数を指定した場合に発生します。

//emlist[例][ruby]{
a = (1..10).to_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]
//}...

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

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

...した場合に発生します。

@raise ArgumentError 引数 n に負の数を指定した場合に発生します。

//emlist[例][ruby]{
a = (1..10).to_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]
//}...

Pathname#split -> Array (114.0)

File.split(self.to_s) と同じです。

...File.split(self.to_s) と同じです。

//emlist[例][ruby]{
require "pathname"

pathname = Pathname("/path/to/sample")
pathname.split # => [#<Pathname:/path/to>, #<Pathname:sample>]
//}

@see File.split...

絞り込み条件を変える

Rake::TaskManager#in_namespace(name) {|name_space| ... } -> Array (114.0)

与えられた名前の名前空間でブロックを評価します。

...ます。

@param name 名前を指定します。

//emlist[][ruby]{
# Rakefile での記載例とする

task default: :test_rake_app

namespace :sample do
def hoge
puts "hoge"
end
end

task :test_rake_app do
task.application.in_namespace("sample") do
hoge # => "hoge"
end
end
//}...

Random#rand -> Float (19.0)

一様な擬似乱数を発生させます。

...ように見える

# 上と同じ種で再初期化
prng = Random.new(1234)
srand(1234)
# Kernel.#rand は Array#sample などの影響を受けて値がずれることがある
[0, 1].sample
prng.rand #=> 0.1915194503788923
rand #=> 0.6221087710398319
//}


@see Kernel...

Random#rand(max) -> Integer | Float (19.0)

一様な擬似乱数を発生させます。

...ように見える

# 上と同じ種で再初期化
prng = Random.new(1234)
srand(1234)
# Kernel.#rand は Array#sample などの影響を受けて値がずれることがある
[0, 1].sample
prng.rand #=> 0.1915194503788923
rand #=> 0.6221087710398319
//}


@see Kernel...

Random#rand(range) -> Integer | Float (19.0)

一様な擬似乱数を発生させます。

...ように見える

# 上と同じ種で再初期化
prng = Random.new(1234)
srand(1234)
# Kernel.#rand は Array#sample などの影響を受けて値がずれることがある
[0, 1].sample
prng.rand #=> 0.1915194503788923
rand #=> 0.6221087710398319
//}


@see Kernel...