0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[学習確認用] Ruby 配列の中からランダムな値を一つ抜き取る

Posted at

配列の中からランダムな値を一つ抜き出す。

number = [1, 3, 4, 5, 11, 12]
nunber_count = number.count
puts number_count

1.times do
     puts number[rand(number_count)]
end

number_count の所は数字でもいけるが配列の数より大きい値を入れると空の値を抜き出してしまうから今回は配列の数をランダムの数に入れている。

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?