title: how to generate random strings twice
body: <pre class="lang-js prettyprint-override"><code>function generate() {
    const notations = [&quot; U&quot;, &quot; D&quot;, &quot; R&quot;, &quot; L&quot;, &quot; F&quot;, &quot; B&quot;];
  
    const switches= [&quot;&quot;, &quot;\'&quot;, &quot;2&quot;]; 
  
    let array = [];
  
    let last = '';
  
    let random = 0;
  
    for (let i = 0; i &lt; 20; i++) {
        
        do {
           random = Math.floor(Math.random() * notations.length);
        } while (last == notations[random]) 
  
  
    last = notations[random];
  
    let Item = notations[random] + switches[parseInt(Math.random()*switches.length)];
  
    array.push(Item);
    }
  
    let scrambles = &quot;&quot;;
  
    for(i=0; i&lt; 20; i++) {
       scrambles += array[i];
    }
  
  document.getElementById(&quot;div&quot;).innerHTML = scrambles;
  }
  </code></pre>
  <p>so i have function that generates random string so output will be something like <code>R U' B2 R2 L F L2 B U2 B U F' L' B2 R' L D2 U' L2 R</code></p>
  <p>and i want to generate the random letters twice  so output will be something like</p>
  <pre><code>R U' B2 R2 L F L2 B U2 B U F' L' B2 R' L D2 U' L2 R
  B R' U' F' D L U2 F' R' B D U F R' L' F U2 D L R
  </code></pre>
  <p>i found a solution which is by duplicating the codes like this</p>
  <pre class="lang-js prettyprint-override"><code>function generate() {
    const notations = [&quot; U&quot;, &quot; D&quot;, &quot; R&quot;, &quot; L&quot;, &quot; F&quot;, &quot; B&quot;];
  
    const switches= [&quot;&quot;, &quot;\'&quot;, &quot;2&quot;]; 
  
    let array = [];
  
    let last = '';
  
    let random = 0;
  
    for (let i = 0; i &lt; 20; i++) {
        
        do {
           random = Math.floor(Math.random() * notations.length);
        } while (last == notations[random]) 
  
  
    last = notations[random];
  
    let Item = notations[random] + switches[parseInt(Math.random()*switches.length)];
  
    array.push(Item);
    }
  
    let scrambles = &quot;&quot;;
  
    for(i=0; i&lt; 20; i++) {
       scrambles += array[i];
    }
  
   const notations2 = new Array(&quot; U&quot;, &quot; D&quot;, &quot; R&quot;, &quot; L&quot;, &quot; F&quot;, &quot; B&quot;);
  
    const switches2= [&quot;&quot;, &quot;\'&quot;, &quot;2&quot;]; 
  
    let array2 = [];
  
    const last2 = '';
  
    const random2 = 0;
  
    for (let i = 0; i &lt; 20; i++) {
        
        do {
           random2 = Math.floor(Math.random() * notations2.length);
        } while (last == notations2[random2]) 
  
  
    last2 = notations2[random2];
  
    let Item2 = notations2[random2] + switches2[parseInt(Math.random()*switches2.length)];
  
    array.push(Item2);
    }
  
    let scrambles2 = &quot;&quot;;
  
    for(i=0; i&lt; 20; i++) {
       scrambles2 += array[i];
    }
  document.getElementById(&quot;div&quot;).innerHTML = scrambles + &quot;&lt;br&gt;&quot; + scrambles2;
  }
  
  </code></pre>
  <p>but its not efficient, is there a faster way and more efficient way to do this?</p>