title: Jumbled, but not random
body: <p>SOLVED <a href="https://stackoverflow.com/questions/45746928/backtracking-algorithm-to-create-a-jumbled-but-not-random-array">here</a></p>
  
  <p>UPDATE.</p>
  
  <p>I have made some progress with this - see code.
  My backtracking algorithm only works every time if the size of my shuffled input array is larger than my output array, but then there is not an equal distribution of items in the output array. If the two arrays are equal in size, it sometimes works and sometimes overflows.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE HTML&gt;
  &lt;html&gt;
  &lt;head&gt;
   &lt;meta http-equiv="content-type" content="text/html" /&gt;
   &lt;meta name="author" content="Ballantyne de Wolf" /&gt;
  
   &lt;title&gt;Backtracking Pseudo Randomiser&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;button onclick=go();&gt;Go&lt;/button&gt;
  
  &lt;script&gt;
  function go() {
     
      function pseudoRan(input,output) {
          if (output.length==70) {
              output=listToMatrix(output,5);
              printIt(output);
              return; 
          }
                  else {
                      var tmp=input.shift();
                      var mod=output.length % 5;
                      if (output.slice(-mod-1).indexOf(tmp)==-1 &amp;&amp; output[output.length-5]!=tmp &amp;&amp; output[output.length-10]!=tmp) {
                          output.push(tmp);
                          pseudoRan(input,output);
                      }
                      else {
                          input.push(tmp);
                          pseudoRan(input,output);
                      }
                      
                  }
                      
                  
      }
      
  var input=["A","B","C","D","E","F","G","H","I","K"];
  var output=[];
  input=pool(input,70);
  input=yatesShuffle(input);
  pseudoRan(input, output);
  
      
      //analyse it
  var freqs=output.byCount();
  var strFreqs="";
  for(a=0;a&lt;freqs.length;a++){
        strFreqs+="Item: " + freqs[a].item + "   ..." + freqs[a].frequency + "&lt;br /&gt;";
        document.getElementById("2").innerHTML=strFreqs;
      }
  }
      
      
  function pool(array,total) {
      var factor=total/array.length;
      var newArray=[];
      for (a=0;a&lt;factor;a++) {
          for (b=0;b&lt;array.length;b++) {
              newArray.push(array[b]);
          }
      }
      //console.log(newArray);
      return newArray;
  }
      
  function yatesShuffle (array) {
      for (var i = array.length - 1; i &gt; 0; i--) {
          var j = Math.floor(Math.random() * i); // no +1 here!
          var temp = array[i];
          array[i] = array[j];
          array[j] = temp;
          }   
      return array;
  }
      
  
  function listToMatrix(list, elementsPerSubArray) {
      var matrix = [], i, k;
  
      for (i = 0, k = -1; i &lt; list.length; i++) {
          if (i % elementsPerSubArray === 0) {
              k++;
              matrix[k] = [];
          }
  
          matrix[k].push(list[i]);
      }
  
      return matrix;
  }
      
  function printIt(array) {
      for (i=0;i&lt;array.length;i++) {
          var str=" ";
          for (j=0;j&lt;array[i].length;j++) {
              str+=array[i][j]+" ";
          }
          document.getElementById("1").insertAdjacentHTML('beforeend',str + "&lt;/br&gt;");
          
          //console.log(array[i]);
      }
  }
  Array.prototype.byCount= function(){
      var itm, a= [], L= this.length, o= {};
      for(var i= 0; i&lt;L; i++){
          itm= this[i];
          if(!itm) continue;
          if(o[itm]== undefined) o[itm]= 1;
          else ++o[itm];
      }
      for(var p in o) a[a.length]= {item: p, frequency: o[p]};
      return a.sort(function(a, b){
          return o[b.item]-o[a.item];
      });
  }
      
  &lt;/script&gt;
  &lt;div id="1" style="font-family:'Courier New';"&gt;&lt;/div&gt;
      &lt;br /&gt;
  &lt;div id="2"&gt;&lt;/div&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I'm writing in Javascript
  I have an array of 10 items</p>
  
  <p>From these 10 items I want to permutate 14 arrays of 5 items each that obey the following rules:</p>
  
  <ol>
  <li>The items "look jumbled" but</li>
  <li>Each of the 10 items is represented exactly 7 times across the 14 arrays</li>
  <li>No item in the same position in any of 3 consecutive arrays</li>
  <li>No more than two common items between 2 consecutive arrays</li>
  </ol>
  
  <p>Now I can do this once by hand, but it's a lot of work to do it 100 times. Can it be done programmatically?</p>
  
  <p>thanks</p>