hi folks,
ive got a little problem…
lets say i have an array called numbers with these values: 0,1,2,3,4,5,6,7,8,9,10
i want to call a random number of that array, something like this:
rand = Math.round(Math.random()*(_root.numbers.length-1));
no = numbers[rand];
then when ive got my value (no) i want to delete it from the array… and thats the problem… i tried to convert the array to a string and then slice it up… but because the ‘10’ has 2 characters it all goes wrong… this is the code i’ve got sofar and i would really appreciate it if you can help me further…
numbers = 11;
answers = new Array();
for (i=0; i<11; i++) {
answers.push(i);
}
Array.prototype.shuffle = function() {
this.sort(function () {
return random(2);
});
};
answers.shuffle();
function bla() {
rand = Math.round(Math.random()*(_root.answers.length-1));
no = answers[rand];
str = answers.toString();
pos = str.indexOf(no);
begin = str.slice(0, pos);
end = str.slice(pos+2);
newstr = begin.concat("", end);
if (answers.length<1) {
trace("that's it");
}
trace(begin + " -- " + no + " -- "+ end);
answers = newstr.split(",");
}