Skip to content

Random

Random number, UUID, choice, and shuffle.

4 modules

ModuleDescription
隨機選擇從陣列中選擇隨機元素
隨機數字在範圍內生成隨機數字
打亂陣列隨機打亂陣列元素
生成 UUID生成隨機 UUID (v4)

Modules

隨機選擇

random.choice

從陣列中選擇隨機元素

Parameters:

NameTypeRequiredDefaultDescription
arrayarrayYes-要從中選擇的陣列
countnumberNo1要從中選擇的陣列
uniquebooleanNoTrue要選擇的元素數量

Output:

FieldTypeDescription
choiceany選擇唯一元素(不重複)
countnumber選擇的元素

隨機數字

random.number

在範圍內生成隨機數字

Parameters:

NameTypeRequiredDefaultDescription
minnumberNo0最小值(包含)
maxnumberNo100最小值(包含)
integerbooleanNoTrue最大值(包含)
precisionnumberNo2僅生成整數

Output:

FieldTypeDescription
numbernumber小數位數
minnumber生成的隨機數字
maxnumber生成的隨機數字

打亂陣列

random.shuffle

隨機打亂陣列元素

Parameters:

NameTypeRequiredDefaultDescription
arrayarrayYes-要打亂的陣列

Output:

FieldTypeDescription
resultarray要打亂的陣列
lengthnumber打亂後的陣列

生成 UUID

random.uuid

生成隨機 UUID (v4)

Parameters:

NameTypeRequiredDefaultDescription
uppercasebooleanNoFalse返回大寫 UUID
remove_hyphensbooleanNoFalse返回大寫 UUID

Output:

FieldTypeDescription
uuidstring移除 UUID 中的連字號
versionnumber生成的 UUID

Released under the Apache 2.0 License.