From 5ef224e2a9b37d4b5b283d5bf5ebd4f5d0ec226b Mon Sep 17 00:00:00 2001 From: Julie Lala Date: Wed, 18 Dec 2013 21:32:42 -0500 Subject: initial commit... --- js/gif-encode/util.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 js/gif-encode/util.js (limited to 'js/gif-encode/util.js') diff --git a/js/gif-encode/util.js b/js/gif-encode/util.js new file mode 100644 index 0000000..92d8129 --- /dev/null +++ b/js/gif-encode/util.js @@ -0,0 +1,15 @@ +function shuffle(a){ + var aa = new Array(a.length); + aa[0] = a[0]; + + for (var i = 1; i < a.length; i++) { + var j = Math.floor( Math.random() * i ); + aa[i] = aa[j]; + aa[j] = a[i]; + } + return aa; +} +function sample(a, n) { + var aa = shuffle(a); + return aa.slice(0,n); +} -- cgit v1.2.3-70-g09d2