1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-16 11:44:50 +02:00

add shuffle

This commit is contained in:
Justin Lin
2021-02-27 20:04:47 +08:00
parent a3be359160
commit b20cfd7b0d

11
src/util/shuffle.scad Normal file
View File

@@ -0,0 +1,11 @@
use <swap.scad>;
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);