SPWN-language icon indicating copy to clipboard operation
SPWN-language copied to clipboard

much faster shuffle

Open makitard opened this issue 2 years ago • 4 comments

makitard avatar Sep 10 '22 21:09 makitard

please

makitard avatar Sep 11 '22 20:09 makitard

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 avatar Sep 12 '22 08:09 SpeckyYT

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.

SpeckyYT avatar Sep 13 '22 06:09 SpeckyYT

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

makitard avatar Sep 13 '22 08:09 makitard