杨前锦
2025-05-15 a1c61b374f66bca12c27872685ff37a33366efb4
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
29
30
31
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
 
namespace HH.WCS.Mobox3.FJJT.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;
        }
    }
}