Spu7Nix / SPWN-language

A language for Geometry Dash triggers
MIT License
1.06k stars 61 forks source link

much faster shuffle #282

Closed makitard closed 1 year ago

makitard commented 2 years ago

please

SpeckyYT commented 2 years ago

We are currently rewriting spwn (check out the RWRT branch) and the std isn't ready yet for rewrite, but this algorithm will still be useful. Keep this code up until we finally get on rewriting the std library.

SpeckyYT commented 2 years ago

Btw, there are two problems with your algorithm.

1) the algorithm can select already shuffled elements, which means that some permutations can occur multiple times (this can be fixed with setting the random index to $.random(i..arr.length)) 2) the temp = a; a = b; b = temp; code is inefficient, a <=> b would be faster.

makitard commented 2 years ago

Btw, there are two problems with your algorithm.

1) the algorithm can select already shuffled elements, which means that some permutations can occur multiple times (this can be fixed with setting the random index to $.random(i..arr.length)) 2) the temp = a; a = b; b = temp; code is inefficient, a <=> b would be faster.

thanks for the feedback. didn't know a <=> b was valid spwn syntax