mirror of
https://github.com/revarbat/BOSL2.git
synced 2025-08-19 09:41:02 +02:00
Added rand_ints() and shuffle()
This commit is contained in:
12
arrays.scad
12
arrays.scad
@@ -244,6 +244,18 @@ function enumerate(l,idx=undef) =
|
||||
[for (i=[0:1:len(l)-1]) concat([i], [for (j=idx) l[i][j]])];
|
||||
|
||||
|
||||
// Function: shuffle(list)
|
||||
// Description:
|
||||
// Shuffles the input list into random order.
|
||||
function shuffle(list) =
|
||||
len(list)<=1 ? list :
|
||||
let (
|
||||
rval = rands(0,1,len(list)),
|
||||
left = [for (i=[0:len(list)-1]) if (rval[i]< 0.5) list[i]],
|
||||
right = [for (i=[0:len(list)-1]) if (rval[i]>=0.5) list[i]]
|
||||
) concat(shuffle(left), shuffle(right));
|
||||
|
||||
|
||||
// Function: sort()
|
||||
// Usage:
|
||||
// sort(arr, [idx])
|
||||
|
Reference in New Issue
Block a user