Advertisement
kberg

Untitled

Feb 16th, 2012
546
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement