User Tools

Site Tools


4rpl:commands:getlistelement

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
4rpl:commands:getlistelement [2021/03/02 18:05] Karsten754rpl:commands:getlistelement [2025/02/14 14:57] (current) – external edit 127.0.0.1
Line 21: Line 21:
     Trace (<-list[I])                #functionally equivalent     Trace (<-list[I])                #functionally equivalent
 loop loop
 +</code>
 +
 +<code 4rpl>
 +# A 2-line code that gets a random element from a provided list.
 +RandInt(0 GetListCount(<-units)) ->randIndex
 +GetListElement(<-units <-randIndex) ->targetUnit
 +</code>
 +
 +<code 4rpl>
 +# A function for selecting a random element from a list:
 +1 2 4 8 16 list ->list
 +
 +<-list @selectRandomElement ->randElement
 +
 +:selectRandomElement
 +Dup
 +Getlistcount 0 swap RandInt
 +Getlistelement 
 </code> </code>
 <=[[4rpl:start| Index]] <=[[4rpl:start| Index]]
  
4rpl/commands/getlistelement.1614708347.txt.gz · Last modified: 2025/02/14 14:56 (external edit)