Demonstrate how to pick a random element from a list.




/* NetRexx */
options replace format comments java crossref savelog symbols nobinary
 
iArray = [ 1, 2, 3, 4, 5 ]     -- a traditional array
iList = Arrays.asList(iArray)  -- a Java Collection "List" object
iWords = '1 2 3 4 5'           -- a list as a string of space delimited words
 
 
v1 = iArray[Random().nextInt(iArray.length)]
v2 = iList.get(Random().nextInt(iList.size()))
v3 = iWords.word(Random().nextInt(iWords.words()) + 1) -- the index for word() starts at one
 
say v1 v2 v3
 