This version is out of date, covering development from v9.5.0 to v9.7.3. It is maintained here only for inbound reference links from elsewhere. It is no longer actively updated.

Jump to the current version of aTbRef

Tinderbox v9 Icon

List/Set.randomItem()


Operator Type: 

Operator Scope of Action: 

Operator Purpose: 

Operator First Added: 

Operator Last Altered: 

 Function  [other Function type actions]

 List  [operators of similar scope]

 Dictionary, Set & List operations  [other Dictionary, Set & List operations operators]

 9.5.2

 As at baseline


Syntax note: Operators without any defined mandatory arguments may omit their empty closing parentheses


List/Set.randomItem()

From v9.5.2, the .randomItem() returns a randomly-selected item from a list (List or Set data types):

$MyString = $MyList.randomItem(); 

This replaces the extra coding needed for such a task if using rand().

This operator can be used not only on attributes but also literal lists using list():

$MyString = list("ant;bee;cow;dog").randomItem(); 

list-based variables:

var:list vList = "ant;bee;cow;dog"; $MyString = vList.randomItem(); 

and list-creating operators:

$MyString = collect(find($SomeAttribute=="xyz"),$Path).randomItem();