C#生成随机的二维码号

using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Text;  
using System.Threading.Tasks;  
  
public class QRCodeGenerator  
{  
    private static readonly string BaseCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";  
    private static readonly Random Random = new Random();  
    private static readonly HashSet GeneratedCodes = new HashSet();  
  
    public static string GenerateUniqueQRCode(int length)  
    {  
        while (true)  
        {  
            string code = GenerateRandomQRCode(length);  
            if (!GeneratedCodes.Contains(code))  
            {  
                GeneratedCodes.Add(code);  
                return code;  
            }  
        }  
    }  
  
    private static string GenerateRandomQRCode(int length)  
    {  
        int maxValue = BaseCharacters.Length - 1;  
        string randomCode = "";  
        for (int i = 0; i < length; i++)  
        {  
            int randomIndex = Random.Next(maxValue);  
            randomCode += BaseCharacters[randomIndex];  
        }  
        return randomCode;  
    }  
}

你可能感兴趣的:(C#,c#,开发语言,java)