Advertisement
angryatti

EuroJackpot Lottery CryptoRandom v2

Nov 10th, 2024 (edited)
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.09 KB | None | 0 0
  1. //IT IS UNDER MIT LICENSE, YOU CAN USE IT ANYWHERE WITHOUT ANY LIMITATION
  2. //THERE IS NO WARRANTY FOR WINNING
  3. using System.Security.Cryptography;
  4.  
  5. namespace EuroJackpotLottery;
  6.  
  7. class Program
  8. {
  9.     static void Main()
  10.     {
  11.         HashSet<uint> setOfLotteryBase = new HashSet<uint>();
  12.         HashSet<uint> setofLotteryBField = new HashSet<uint>();
  13.         int numbofGen = 0;
  14.  
  15.         Console.WriteLine("Generating lottery fields, but How much field? Enter number of lottery fields: ");
  16.         while (numbofGen <= 0)
  17.         {
  18.             Console.WriteLine("Give number:");
  19.             if (int.TryParse(Console.ReadLine(), out int numbGen))
  20.             {
  21.                 numbofGen = numbGen;
  22.             }
  23.             else
  24.             {
  25.                 Console.WriteLine("Invalid number!");
  26.             }
  27.         }
  28.  
  29.         for (int i = 0; i < numbofGen; i++)
  30.         {
  31.             while (setOfLotteryBase.Count < 5)
  32.             {
  33.                 setOfLotteryBase.Add(GetRandomIntSecure(1, 50));
  34.             }
  35.  
  36.             while (setofLotteryBField.Count < 2)
  37.             {
  38.                 setofLotteryBField.Add(GetRandomIntSecure(1, 12));
  39.             }
  40.  
  41.             Console.WriteLine(
  42.                 $"Lottery Base: A-Field {string.Join(", ", setOfLotteryBase.OrderBy(element => element).ToList())} B-Field {string.Join(", ", setofLotteryBField.OrderBy(element => element).ToList())}");
  43.  
  44.             setOfLotteryBase.Clear();
  45.             setofLotteryBField.Clear();
  46.         }
  47.     }
  48.  
  49.  
  50.     private static uint GetRandomIntSecure()
  51.     {
  52.         using (var trng = RandomNumberGenerator.Create())
  53.         {
  54.             byte[] randomData = new byte[4];
  55.             trng.GetBytes(randomData);
  56.             // trng.Dispose();
  57.             return BitConverter.ToUInt32(randomData);
  58.         }
  59.     }
  60.  
  61.     private static uint GetRandomIntSecure(uint min, uint max)
  62.     {
  63.         uint validNumberRange = max - min + 1;
  64.         uint mod = GetRandomIntSecure() % validNumberRange;
  65.         mod = mod * 1;
  66.         uint result = min + mod;
  67.         return result == 0 ? 1 : result;
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement