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,368
Reaction score
1,403
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

Make a Game in RMMZ Streams are going to remain in hiatus this week. Too much to do! 4 things will be announced on Monday though! Look forward to that.
Typed a long-ish reply to a post... forgot to actually HIT the post button, and moved to a different page.... finally noticed, don't remember what all I had typed and don't feel like trying to re-type it all.... smh....
Their tactics are evolving. They've learned to call for help when cornered. Never trust a mammal!
Good morning all. I still have a post up on video editing for cinematic trailers. Please make sure to check that out and give me a message as its still active in offers.
Hey everyone! I'm back :D

Snow White? More like Snowhere to be seen amiright? Hahaha I'm so sorry!! :kaocry:

Forum statistics

Threads
112,371
Messages
1,067,841
Members
146,017
Latest member
Anselmo00
Top