random_choice()#

Select a random item from a list.

Examples#

1def setup():
2    words = ["apple", "bear", "cat", "dog"]
3    word = py5.random_choice(words)
4    py5.println(word)  # Prints one of the four words

Description#

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.

Syntax#

random_choice(objects: list[Any]) -> Any

Parameters#

  • objects: list[Any] - list of objects to choose from

Updated on March 01, 2022 12:15:01pm UTC