mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-01-29 11:58:39 +01:00
add choose
This commit is contained in:
parent
49b3425bc1
commit
0d246f1a22
16
docs/lib2x-choose.md
Normal file
16
docs/lib2x-choose.md
Normal file
@ -0,0 +1,16 @@
|
||||
# choose
|
||||
|
||||
Choose an element from the given list randomly.
|
||||
|
||||
**Since:** 2.5
|
||||
|
||||
## Parameters
|
||||
|
||||
- `choices` : The list to choose from.
|
||||
- `seed` : Random seed value.
|
||||
|
||||
## Examples
|
||||
|
||||
use <util/choose.scad>;
|
||||
|
||||
echo(choose([1, 2, 3, 4]));
|
13
src/util/choose.scad
Normal file
13
src/util/choose.scad
Normal file
@ -0,0 +1,13 @@
|
||||
/**
|
||||
* choose.scad
|
||||
*
|
||||
* @copyright Justin Lin, 2021
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
* @see https://openhome.cc/eGossip/OpenSCAD/lib2x-choose.html
|
||||
*
|
||||
**/
|
||||
|
||||
function choose(choices, seed) =
|
||||
let(c = is_undef(seed) ? rands(0, len(choices) - 1, 1) : rands(0, len(choices) - 1, 1, seed))
|
||||
choices[round(c[0])];
|
Loading…
x
Reference in New Issue
Block a user