random The module is Python A module used to obtain random numbers Because it is randomly acquired , So the structure of each output may be different
Code example :
# Before using , Import the module first import random# Random acquisition of one of a set of data x = random.choice([10,58,39,78,96,12])y = random.choice(range(10))z = random.choice('helloworld')print(x, y, z)# Generate a random number in a specified range # It is slightly different from the above method # random.randrange(start,end,step)# start: Starting position # end: End position # step: step # The specified range obtained by this method is the same as range() In the same way m = random.randrange(1,10,2)# Pick one at random 1-10 Odd number in print(m)# Generate a 0-1 The random number , Is a floating point number n = random.randm()print(n)# Randomly generate a real number within a specified range , The result is a floating-point number s = random.uniform(6,23)print(s)# Randomly sort a set of data l1 = [10,25,89,296,12,23,132,5]l2 = random.shuffle(l1)print(l2)
author :(#`O′) all
Game programming , A game development favorite ~
If the picture is not displayed for a long time , Please use Chrome Kernel browser .