Select a random item from a list.
1 2 3 4
def setup(): words = ["apple", "bear", "cat", "dog"] word = py5.random_choice(words) py5.println(word) # Prints one of the four words
Select a random item from a list. The list items can be of any type. This function’s randomness can be influenced by random_seed().
This function makes calls to numpy to select the random items.
random_choice(objects: list[Any]) -> Any
objects: list[Any] - list of objects to choose from
Updated on March 01, 2022 12:15:01pm UTC