I've been experimenting with various methods for some time now, but I've hit a wall where everything I try seems to go wrong.
Here's what I attempted: Firstly, I generate a random number and add it to an array:
for(.......){
random[i] = Math.floor(Math.random() * (word.length));
Next, another random number is appended to the array:
randomkey[i] = Math.floor(Math.random() * (word.length));
Following that, I create a function:
var accept=true;
// word is a text (length:22)
function acceptRandom(random,word){
stop:
for(var i=0;i<randomkey.length+1; i++){
if(word[i] != word[random])
accept = true;
else {
accept = false;
break stop;
}
}
if(accept == false){
newrandom = Math.floor(Math.random() * (word.length));
// Random number exists so we call the function again with a new value
acceptRandom(newrandom,word);
} else
return random;
}
The issue now is that it doesn't provide a new value when the random number already exists.