Choose random element from an array

AnyLogic provides functions to select a random element from a given array. These functions are defined in the class Utilities and are global (accessible from each place of model code). You call any function from the list below by typing just its name, without a prefix with the array name: randomWhere( people, p -> p.income > 10000 ); 

T randomFrom( T[] array ) -  Returns a randomly chosen element of the given array (or null if the array is empty). This result of this method is an equivalent of calling: array[ uniform_discr( array.length - 1 ) ]

T randomFrom( T[] array, java.util.Random r ) -  Similar to randomFrom( T[] array ). Uses the specified custom random number generator to choose the element.

T randomWhere( T[] array, condition ) -  Returns a randomly chosen element within the given array satisfying the specified condition. If the array is empty or no elements satisfy the specified condition(s), the function returns null.

T randomWhere( T[] array, condition, java.util.Random r ) -  Similar to randomWhere( T[] array, condition ). Uses the specified custom random number generator to choose the element.