xabileug

Veteran
Veteran
Joined
Jul 1, 2014
Messages
178
Reaction score
38
I'm testing the fisher yates shuffle on this online editor
JavaScript:
var t0 = [0,0,0,0,0,0,0,0,0,0,0,0,0];
var t1 = [1,1,1,1,1,1,1,1,1,1,1,1,1];
var t2 = [2,2,2,2,2,2,2,2,2,2,2,2,2];
var t3 = [3,3,3,3,3,3,3,3,3,3,3,3,3];
var t4 = t0.concat(t1,t2,t3);

console.log(t4);

var pp = t4; // array cards
for (var i = pp.length - 1; i > 0; i--) {
    const swapIndex = Math.floor(Math.random() * (i + 1))
    const currentCard = pp[i]
    const cardToSwap = pp[swapIndex]
    pp[i] = cardToSwap
    pp[swapIndex] = currentCard
  }
console.log(pp);
console.log(pp[0]);console.log(pp[4]);console.log(pp[8]);console.log(pp[12]);

this is the output.. as you can see the array is shuffled correctly..
1620271308288.png
however in RMMV..
1620271364958.png
this is the output.. i dont know what is wrong
1620271453676.png
 

estriole

Veteran
Veteran
Joined
Jun 27, 2012
Messages
1,501
Reaction score
727
First Language
indonesian
I think maybe the last show text should be \v[5] instead...?
since you store pp to variable 5...

i don't see any other problem though...
 

xabileug

Veteran
Veteran
Joined
Jul 1, 2014
Messages
178
Reaction score
38
I think maybe the last show text should be \v[5] instead...?
since you store pp to variable 5...

i don't see any other problem though...
it's still the same i tried \v[4] \v[5], on that line, and they output the same.. its like the shuffle is only done once..

EDIT:
I swapped with another version of fisher yates.. this once works
JavaScript:
var i = arr.length, j, temp;
while(--i > 0){
    j = Math.floor(Math.random()*(i+1));
    temp = arr[j];
    arr[j] = arr[i];
    arr[i] = temp;
}
 
Last edited:

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,371
Reaction score
1,404
First Language
Spanish
Primarily Uses
RMVXA
generically:
Code:
i = t4[random(t4.length-1)]
pp.unshift(t4.pop(i))

get total of items.
randomize based on total.
remove index number from total -> total decreases by 1.
repeat.

you don't need to reorder pp, you need to create pp based on the items of t4.
this
JavaScript:
var i = arr.length, j, temp;
while(--i > 0){
    j = Math.floor(Math.random()*(i+1));
    temp = arr[j];
    arr[j] = arr[i];
    arr[i] = temp;
}

is the bubble method for sorting.
 

xabileug

Veteran
Veteran
Joined
Jul 1, 2014
Messages
178
Reaction score
38
generically:
Code:
i = t4[random(t4.length-1)]
pp.unshift(t4.pop(i))
is this shorter method? this is for deck of cards. im making a game dealing cards, players get 4 cards on their hand.
 

Latest Threads

Latest Posts

Latest Profile Posts

MrSaturnMZ.png Can confirm that Mr. Saturn is appearing in Vtubers Vs MOTHER and here's the MV/MZ compatible sprite sheet for them.
Final Fantasy IX is apparently getting an animated adaptation - coming from IGN, so this news has bite to it. FF9 is one of the best turn-based RPGs ever imo. https://www.ign.com/articles/final-fantasy-9-animated-series-announced
I hope everyone is well. Just a quick update, I am working on my college degree right now so that's why I've delayed a lot of my Old RPG maker projects until further notice. I hope you're all making good progress and that you have fun working on them gems. Keep hammering away.
Don't think I can ignore this anymore, but it only happens like once a day. Not sure why my entire pc slows down though, its using a lot of memory but not compared to my max. Seem the thread about updating the nwjs it a while ago, it just looked like a pain/tldr :p
nwjs.PNG

Forum statistics

Threads
112,429
Messages
1,068,238
Members
146,085
Latest member
AkaiAmeUltsch
Top