程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Learning notes: random module of Python

編輯:Python

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 .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved