Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

Ruby | Array | shuffle

概要

Array#shuffle

詳細

配列の要素をシャッフルする。

サンプルコード

# encoding: utf-8

ary = %w[1 2 3 4 5]

5.times {
  print ary.shuffle
  puts
}

出力

["5", "4", "2", "1", "3"]
["2", "3", "4", "5", "1"]
["2", "5", "1", "3", "4"]
["2", "5", "4", "3", "1"]
["4", "3", "1", "5", "2"]