Demonstrate how to pick a random element from a list.




go =>
 
  % single element
  println(choice=choice(10)), % single element
 
  % From a list of numbers
  L = 1..10,
  println([choice(L) : _ in 1..10]),
 
  % From a string
  S = "pickrandomelement",
  println([choice(S) : _ in 1..10]),
  nl.
 
% Pick a random number from 1..N
choice(N) = random(1,N), integer(N) => true.
 
% Pick a random element from a list L.
choice(List) = List[choice(List.length)], list(List) => true.