This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| 4rpl:commands:getlistelement [2021/03/02 18:05] – Karsten75 | 4rpl:commands:getlistelement [2025/02/14 14:57] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 21: | 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  | ||
| </ | </ | ||
| < | < | ||