diff --git a/src/util/shuffle.scad b/src/util/shuffle.scad new file mode 100644 index 00000000..7361b9e6 --- /dev/null +++ b/src/util/shuffle.scad @@ -0,0 +1,11 @@ +use ; + +function shuffle(lt, seed) = + let( + leng = len(lt), + indices = [for(i = is_undef(seed) ? rands(0, leng, leng) : rands(0, leng, leng, seed)) floor(i)] + ) + _shuffle(lt, indices, leng); + +function _shuffle(lt, indices, leng, i = 0) = + i == leng ? lt : _shuffle(swap(lt, i, indices[i]), indices, leng, i + 1); \ No newline at end of file