Shuffle (xxx,true) not doing what docs say

Normally if you shuffle an array with shuffle(array) you are not guaranteed that the array isn't exactly the same as what you sterted with, but the docs say that if you pass a second param TRUE, then the shuffle will at lease make sure 1 element is different than the original.

Well.. when I pass true, then shuffle just returns me exactly the same array as the source array, shuffling nothing.

Works for us - make sure that you pass true, not TRUE.

const a = [1,2,3];
loop(50, ()=>{
	const aa = copy(a)
	shuffle(aa, true)
	zog(aa.toString())
})	

Hehe i am king of the unreproducable problems that I can reproduce :wink:

This code

                for (let rij = 1; rij <= rijen; rij++) {
                    for (let kolom = 1; kolom <= kolommen; kolom++) {
                        teller++;
                        tegelPosities.push({ x: tegelStartX + (tegelBreedte + 5) * (kolom - 1), y: tegelStartY + (tegelHoogte + 5) * (rij - 1) });
                    }
                }
                shuffle(tegelPosities, true);

This code does not shuffle. Is it maybe because of the type of content I push onto the array ?

Oh... what are you shuffling in your array?

Still works with DisplayObjects...

image

const a = [new Circle(), new Rectangle(), new Triangle()];
const items = []
loop(20, ()=>{
	const aa = copy(a, true)
	shuffle(aa, true)
	items.push(...aa);
})	
new Tile(items, 3,20, 10,5, true).scaleTo(S,90,90).center()

See above. I shuffle objects I think they are called.

I think they are objects with x and y property ? Is that how they are called ?

1 Like

Okay - we have adjusted shuffle() so it works with object literals. Thanks for pointing it out. We will wait to clear up that other issue before setting the patch live.

1 Like

You can do a refresh and let us know if the shuffle with the true for no repeat worked. Cheers.

with the same 017 link ?

I can confirm that now shuffle does what it is supposed to do with param true

2 Likes