Tjiny
2025-06-17 7e47d1856a1db4367ce103a8b7de37fb0f3590b0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System;
using System.Security.Cryptography;
 
namespace HH.WCS.Mobox3.RiDong.util;
 
internal class StrHelper
{
    /// <summary>
    /// 获取随机字符串
    /// </summary>
    /// <param name="prefix"></param>
    /// <param name="Length"></param>
    /// <returns></returns>
    public static string StrRandom(string prefix, int Length)
    {
        byte[] b = new byte[32];
        RandomNumberGenerator.Create().GetBytes(b);
        Random random = new Random(BitConverter.ToInt32(b, 0));
        string str = "0123456789"; //abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
        string returnStr = string.Empty;
        for (int i = 0; i < Length; i++)
        {
            returnStr += str.Substring(random.Next(0, str.Length - 1), 1);
        }
        var cntrCode = prefix + returnStr;
        return cntrCode;
    }
}