RandomHelper.cs 705 B

12345678910111213141516171819202122232425
  1. using System;
  2. using System.Text;
  3. namespace ZR.Infrastructure.Helper
  4. {
  5. public class RandomHelper
  6. {
  7. /// <summary>
  8. /// 生成n为验证码
  9. /// </summary>
  10. /// <param name="Length"></param>
  11. /// <returns></returns>
  12. public static string GenerateNum(int Length)
  13. {
  14. char[] constant = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
  15. StringBuilder newRandom = new(constant.Length);
  16. Random rd = new();
  17. for (int i = 0; i < Length; i++)
  18. {
  19. newRandom.Append(constant[rd.Next(constant.Length - 1)]);
  20. }
  21. return newRandom.ToString();
  22. }
  23. }
  24. }