Groovy: Generate random string from given character set

后端 未结 6 487
温柔的废话
温柔的废话 2021-01-31 14:33

Using Groovy, I\'d like to generate a random sequence of characters from a given regular expression.

  • Allowed charaters are: [A-Z0-9]
  • Length o
6条回答
  •  一向
    一向 (楼主)
    2021-01-31 15:10

    Create a string with your alphabet, then do this 9 times:

    1. Create a random number
    2. Find the corresponding character in your alphabet.
    3. Append it to the result

提交回复
热议问题