跳至主要內容

生成隨機字串 (string.random)

聲明

隨機字串 = string.random(字元池 [, 生成字元個數, 每字元的位元組數 ])

參數

  • 字元池
    文字型,需要生成字串的字典
  • 生成字元個數
    整數型,可選參數,需要生成的隨機字串中的字元個數,預設 6
  • 每字元的位元組數
    整數型,可選參數,每個字元的長度,預設 1

回傳值

  • 隨機字串
    文字型,返回生成的隨機字串

說明

生成隨機字串,UTF-8 編碼的中文每個字元的長度為 3

範例

rs = string.random("qwertyuiopasdfghjklzxcvbnm", 20, 1)
rs = string.random("一二三四五六七八九十", 20, 3)