Randomizing now checks that the randomized index is different from the current one

This commit is contained in:
Tailszefox 2024-09-01 19:22:13 +02:00
parent 99f1dcb58e
commit 293485eb4e

View file

@ -66,10 +66,18 @@ $(function ()
var nbPonies = $("#from option").size();
function getRandomIndex(currentIndex, maxIndex) {
var newIndex;
do {
newIndex = Math.floor(Math.random() * maxIndex);
} while (newIndex === currentIndex);
return newIndex;
}
if(which == 0)
{
$("#from")[0].selectedIndex = Math.floor(Math.random() * nbPonies);
$("#to")[0].selectedIndex = Math.floor(Math.random() * nbPonies);
$("#from")[0].selectedIndex = getRandomIndex($("#from")[0].selectedIndex, nbPonies);
$("#to")[0].selectedIndex = getRandomIndex($("#to")[0].selectedIndex, nbPonies);
if($("#from")[0].selectedIndex == $("#to")[0].selectedIndex)
{
@ -81,7 +89,7 @@ $(function ()
}
else if(which == 1)
{
$("#from")[0].selectedIndex = Math.floor(Math.random() * nbPonies);
$("#from")[0].selectedIndex = getRandomIndex($("#from")[0].selectedIndex, nbPonies);
if($("#from")[0].selectedIndex == $("#to")[0].selectedIndex)
{
@ -93,7 +101,7 @@ $(function ()
}
else if(which == 2)
{
$("#to")[0].selectedIndex = Math.floor(Math.random() * nbPonies);
$("#to")[0].selectedIndex = getRandomIndex($("#to")[0].selectedIndex, nbPonies);
if($("#from")[0].selectedIndex == $("#to")[0].selectedIndex)
{