mirror of
https://github.com/Tailszefox/Pony-Fusion.git
synced 2024-11-26 23:47:59 +01:00
Randomizing now checks that the randomized index is different from the current one
This commit is contained in:
parent
99f1dcb58e
commit
293485eb4e
1 changed files with 12 additions and 4 deletions
16
js/base.js
16
js/base.js
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue