SHARE
TWEET

randomSelectSomeFromTotal

a guest Apr 30th, 2013 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fuction randomSelectSomeFromTotal(some, total) {
  2.         var a = new Array();
  3.         var b = new Array();
  4.         for (var i = 0; i < total; i++) a[i] = i;
  5.         for (var j, x, i = a.length; i; j = parseInt(Math.random() * i), x = a[--i], a[i] = a[j], a[j] = x);
  6.         for (var i = 0; i < some; i++) b[i] = a[i];
  7.         return b.sort(function(a, b) {
  8.                 return a - b
  9.         });
  10. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top