This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
4rpl:commands:getlistelement [2021/01/08 16:01] – external edit 127.0.0.1 | 4rpl:commands:getlistelement [2025/02/14 14:57] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ~~NOTOC~~ | + | \\ |
+ | < | ||
< | < | ||
+ | <WRAP tabs> | ||
+ | * [[4rpl: | ||
+ | * [[4rpl: | ||
+ | </ | ||
====== GetListElement ====== | ====== GetListElement ====== | ||
GetListElement (<-list I) -> | GetListElement (<-list I) -> | ||
Line 17: | Line 21: | ||
Trace (< | Trace (< | ||
loop | loop | ||
+ | </ | ||
+ | |||
+ | <code 4rpl> | ||
+ | # A 2-line code that gets a random element from a provided list. | ||
+ | RandInt(0 GetListCount(< | ||
+ | GetListElement(< | ||
+ | </ | ||
+ | |||
+ | <code 4rpl> | ||
+ | # A function for selecting a random element from a list: | ||
+ | 1 2 4 8 16 list ->list | ||
+ | |||
+ | <-list @selectRandomElement -> | ||
+ | |||
+ | : | ||
+ | Dup | ||
+ | Getlistcount 0 swap RandInt | ||
+ | Getlistelement | ||
</ | </ | ||
< | < | ||