Thanks @Yoshi for suggestion
<input id="code">
<button onclick="createUserArray()">CREATE ARRAY</button>
<button onclick="newUserCode()">NEW CODE</button>
<script>
newUserCode() // create new 6-digits code onload
function newUserCode(){
let code = Math.floor(Math.random() * 1000000);
document.getElementById('code').value = addZeros(code)
}
function addZeros(code) { // constant length: adding 0s if needed
let full_code = code.toString();
while ( full_code.length < 6 ) { full_code = "0" + full_code };
return full_code;
}
function createUserArray(){
let code_user = parseInt( document.getElementById('code').value ),
new_array = createArray( code_user );
console.log(new_array.join(','));
}
function createArray(code) {
let basic_array = Array.from({length:51},(v,k)=>k)
let m = basic_array.length, t, i;
while (m) {
i = Math.floor(randomSeed(code) * m--);
t = basic_array[m];
basic_array[m] = basic_array[i];
basic_array[i] = t;
++code
}
return basic_array;
}
function randomSeed(code) {
let x = Math.sin(code++);
return x - Math.floor(x);
}
// 416444 = [9,33,44,38,31,5,37,19,...,23,0,20,18,49,35]
// 663684 = [41,39,4,34,47,31,...1,32,30,46,19,22,0,23]
// 098141 = [48,42,4,34,16,18,...,0,23,21,46,28,31,1,14]