From 54004e39cf19a14254b45208d8e330de67c782b1 Mon Sep 17 00:00:00 2001 From: Heng Li Date: Wed, 6 Apr 2011 12:19:14 -0400 Subject: [PATCH] added table.shuffle() --- lua/klib.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lua/klib.lua b/lua/klib.lua index 5421d4e..ecb8baf 100644 --- a/lua/klib.lua +++ b/lua/klib.lua @@ -39,6 +39,7 @@ string:split() io.xopen() table.ksmall() + table.shuffle() math.lgamma() >math.lbinom() >math.igamma() math.igamma() matrix.chi2() math.erfc() @@ -163,6 +164,13 @@ function table.ksmall(arr, k) end end +function table.shuffle(a) + for i = #a, 1, -1 do + local j = math.random(i) + a[j], a[i] = a[i], a[j] + end +end + -- -- Mathematics -- -- 2.47.3