function generate(n) { const notations = [" U", " D", " R", " L", " F", " B"]; const switches = ["", "\'", "2"]; let last = null; let scrambles = ""; for (let i = 0; i < n; ++i) { //subtract 1 when you can't select the same as the last let available_notations = notations.length - (last === null ? 0 : 1); //one random for all combinations let random = Math.floor(Math.random() * available_notations * switches.length); let nt = Math.floor(random / switches.length); //notation value let sw = Math.floor(random % switches.length); //switch value if (last !== null && last <= nt) nt += 1; //add 1 when value bigger than last last = nt; scrambles += notations[nt] + switches[sw]; } return scrambles; } so i have this code which will generate random strings like thisB U F' D' F2 L2 R F2 L2 B F' D2 U2 L' D' R' L2 F D R but they all generate with the same length which is whatever i put as n on the for loop
but i want the length to vary from a specfic number until a specfic number like for example i want it to generate with length of 20 until 25
nto the function, you can pass amin(e.g.20) and amax(e.g.25) to generate a randomn. You can see how on MDN