mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-16 11:44:50 +02:00
add shuffle
This commit is contained in:
11
src/util/shuffle.scad
Normal file
11
src/util/shuffle.scad
Normal 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);
|
Reference in New Issue
Block a user