Module: DangoUtilModule

Defined in:
lib/dango/framework_base.rb

Overview

ユーティティ

Instance Method Summary collapse

Instance Method Details

#array_random(arr, num = 2) ⇒ Object

配列をランダムに並べ替え arrは順番を入れ替えたい配列 numは入れ替え回数(省略時2、大きな数を入れると確実にランダムになるが時間が掛かる)



89
90
91
92
93
94
95
96
97
98
99
# File 'lib/dango/framework_base.rb', line 89

def array_random(arr, num = 2)
  arr.sort_by{rand}.deep_dup

#    ret_arr = arr.deep_dup
#    (ret_arr.size * num).times do # メンバー数のnum倍の回数、入れ替え
#      idx = rand(ret_arr.size)
#      id = ret_arr.delete_at(idx)
#      ret_arr.push(id)
#    end
#    ret_arr
end