我想要生成一個隨機數並與另一個數進行比較,如果它們相同,我希望隨機數增加1,然後將其添加到舞臺上。但是如果它不同於我想讓它直接添加到舞臺上。但如果數字相同,它不能正常工作,它會通過radomize ++,但仍然會添加生成的初始數字。可以somebnody請幫助我如何解決這個問題?Number generation going wrong
function randomizedorder()
{
randomize = Math.floor(Math.random() * (choices.length));
trace("the random number is" + randomize);
if (randomize == indexcount) {
randomize++;
trace ("it goes through this pahse" + randomize);
}
else {
addChild(choices [randomize]);
}
}
不知道什麼是錯的代碼在這裏看起來okayish。我認爲你應該考慮事先隨機/加擾列表。也許克隆數組,然後隨機選擇隨機交換n個點,然後使用克隆數組添加(和檢查)子項。 – shaunhusain 2013-05-06 18:37:56