1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-03-14 19:19:47 +01:00
This commit is contained in:
Justin Lin 2021-03-07 09:31:14 +08:00
parent ac8ffb31df
commit 9da95c39bc
2 changed files with 16 additions and 5 deletions

View File

@ -0,0 +1,4 @@
use <../swap.scad>;
function _shuffle(lt, indices, leng, i = 0) =
i == leng ? lt : _shuffle(swap(lt, i, indices[i]), indices, leng, i + 1);

View File

@ -1,4 +1,14 @@
use <swap.scad>;
/**
* shuffle.scad
*
* @copyright Justin Lin, 2021
* @license https://opensource.org/licenses/lgpl-3.0.html
*
* @see https://openhome.cc/eGossip/OpenSCAD/lib3x-shuffle.html
*
**/
use <_impl/_shuffle_impl.scad>;
function shuffle(lt, seed) =
let(
@ -6,6 +16,3 @@ function shuffle(lt, seed) =
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);