Pick random element: Difference between revisions
Content deleted Content added
m →{{header|REXX}}: added note about version 2 not working for some REXXes. -- ~~~~ |
→{{header|NetRexx}}: Add a more Rexx like list of words |
||
Line 279:
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
</lang>
|