This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: kberg on Feb 16th, 2012  |  syntax: JavaScript  |  size: 0.52 KB  |  views: 169  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.   function generate(size) {
  2.     var arry = ints(size);
  3.     return compute(arry, []);
  4.   }
  5.  
  6.   function compute(src, dest) {
  7.     if (src.length == 0) {
  8.       return dest;
  9.     }
  10.     dest = dest.concat(src.splice(random(src.length)));
  11.     return compute(src, dest);
  12.   }
  13.  
  14.   function random(n) {
  15.     return Math.floor(Math.random() * n);
  16.   }
  17.  
  18.   // Creates List of size ints from 0-size - 1
  19.   function ints(size) {
  20.     return (size == 1) ? [0] : ints(size - 1).concat(size - 1);
  21.   }
  22.  
  23.   console.log(generate(10));
clone this paste RAW Paste Data