vb.net Create() 创建生成无符号带数字和字母随机数据的加密随机数和每行备注
时间: 2024-02-17 11:01:38 浏览: 67
以下是一个示例代码,可以生成指定数量、长度为16字节的无符号带数字和字母随机数据,并在每行添加备注:
```
Imports System.Security.Cryptography
Imports System.Text
Public Shared Function CreateRandomStrings(ByVal count As Integer, ByVal length As Integer, ByVal remark As String) As List(Of String)
Dim randomStrings As New List(Of String)
For i As Integer = 1 To count
Dim randomBytes(length - 1) As Byte
Using rng As RandomNumberGenerator = RandomNumberGenerator.Create()
rng.GetBytes(randomBytes)
End Using
Dim base64String As String = Convert.ToBase64String(randomBytes)
Dim randomString As String = base64String.TrimEnd("="c).Replace("+"c, "-"c).Replace("/"c, "_"c)
randomStrings.Add(randomString & " " & remark)
Next
Return randomStrings
End Function
```
该函数将生成指定数量的随机字符串,每个字符串的长度为 `length`,并在每行添加指定的备注 `remark`。每个随机字符串将由长度为16字节的随机字节数组生成,并进行 Base64 编码,然后将一些字符替换为 URL 安全字符。最后,将每个随机字符串和备注添加到列表中并返回。
阅读全文