Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //IT IS UNDER MIT LICENSE, YOU CAN USE IT ANYWHERE WITHOUT ANY LIMITATION
- //THERE IS NO WARRANTY FOR WINNING
- using System.Security.Cryptography;
- namespace EuroJackpotLottery;
- class Program
- {
- static void Main()
- {
- HashSet<uint> setOfLotteryBase = new HashSet<uint>();
- HashSet<uint> setofLotteryBField = new HashSet<uint>();
- int numbofGen = 0;
- Console.WriteLine("Generating lottery fields, but How much field? Enter number of lottery fields: ");
- while (numbofGen <= 0)
- {
- Console.WriteLine("Give number:");
- if (int.TryParse(Console.ReadLine(), out int numbGen))
- {
- numbofGen = numbGen;
- }
- else
- {
- Console.WriteLine("Invalid number!");
- }
- }
- for (int i = 0; i < numbofGen; i++)
- {
- while (setOfLotteryBase.Count < 5)
- {
- setOfLotteryBase.Add(GetRandomIntSecure(1, 50));
- }
- while (setofLotteryBField.Count < 2)
- {
- setofLotteryBField.Add(GetRandomIntSecure(1, 12));
- }
- Console.WriteLine(
- $"Lottery Base: A-Field {string.Join(", ", setOfLotteryBase.OrderBy(element => element).ToList())} B-Field {string.Join(", ", setofLotteryBField.OrderBy(element => element).ToList())}");
- setOfLotteryBase.Clear();
- setofLotteryBField.Clear();
- }
- }
- private static uint GetRandomIntSecure()
- {
- using (var trng = RandomNumberGenerator.Create())
- {
- byte[] randomData = new byte[4];
- trng.GetBytes(randomData);
- // trng.Dispose();
- return BitConverter.ToUInt32(randomData);
- }
- }
- private static uint GetRandomIntSecure(uint min, uint max)
- {
- uint validNumberRange = max - min + 1;
- uint mod = GetRandomIntSecure() % validNumberRange;
- mod = mod * 1;
- uint result = min + mod;
- return result == 0 ? 1 : result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement