Current location - Training Enrollment Network - Books and materials - How to Use Random Library in Turtle Editor
How to Use Random Library in Turtle Editor
Hello, to use the random library in Turtle Editor, you need to install a library named Random, which can be found in Python official website. After the installation is completed, you can use the random.randint () function to generate random numbers. This function takes two parameters, one is the minimum value and the other is the maximum value, and it returns a random integer between the minimum value and the maximum value. You can also use the random.choice () function to randomly select an element from the list. In addition, you can use the random.shuffle () function to randomly arrange the elements in the list. In addition, you can use the random.sample () function to randomly select multiple elements from the list. In a word, it is easy to generate random numbers in the turtle editor by using the random library, and it is also easy to randomly select elements from the list.