Skip to content

Commit 88dcd23

Browse files
committed
screenshot: ExtraDebugDetails
1 parent 96eac32 commit 88dcd23

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
Name:
3+
List_Random
4+
5+
Description:
6+
Randomly select items in a list [2021-04-24]
7+
8+
If a list has 3 elements, this generates a random int
9+
in the range [0-2] (inclusive), then returns list{i}
10+
11+
Alias:
12+
python uses the name: random.choice( <list> )
13+
14+
Example:
15+
16+
List_Random( {"Dog", "Cat", "Fish"} )
17+
// returns: "Cat"
18+
19+
future:
20+
- [ ] validate empty list, or null, or null in list
21+
- [ ] nicer user-facing errors
22+
*/
23+
24+
(source as list) as any =>
25+
let
26+
maxIndex = List.Count(source) - 1,
27+
offset = List.Random(1){0} * maxIndex,
28+
r = Number.Round( offset, null, null ),
29+
name = source{r}
30+
in
31+
name

0 commit comments

Comments
 (0)