LoginSignup
1
0

More than 5 years have passed since last update.

ランダムな値を被らないように出力したい

Last updated at Posted at 2018-01-03

randで出力した場合、一回出た値がもう一度でる可能性がある

array_nums = [*1..1000] # 1~1000の数字の配列
array_nums.count.times do |t|
  puts array_nums.delete_at(rand(array_nums.count)) # array_numsからランダムに一つ値が削除されるため一度出力した値が出力されない
end
1
0
3

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
1
0