Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- class LCG
- {
- static void Main()
- {
- Console.Write("Enter Initial SEED : 0x"); // 初期SEED入力
- if (uint.TryParse(Console.ReadLine(), System.Globalization.NumberStyles.HexNumber, null, out uint Seed))
- {
- Console.Write("Enter SEED Count :");
- if (int.TryParse(Console.ReadLine(), out int count) && count > 0)
- {
- Console.Write("Enter File Name :");
- string outputPath = Console.ReadLine();
- using (StreamWriter writer = new(outputPath))
- {
- for (int i = 0; i < count; i++, Seed = NextSeed(Seed))
- {
- uint lsr = Seed >> 16;
- uint mod = lsr % 100;
- int n = 0;
- //Console.WriteLine($"Iteration {i}: Seed = 0x{Seed:X8}, mod = {mod}");
- if (mod <= 34)
- {
- uint ASeed = Seed;
- uint Amod;
- do
- {
- ASeed = NextSeed(ASeed);
- uint Alsr = ASeed >> 16;
- Amod = Alsr % 100;
- // Console.WriteLine($"Loop {n}: ASeed = 0x{ASeed:X8}, Amod = {Amod}");
- if (63 <= Amod && Amod <= 99)
- {
- n++;
- ASeed = NextSeed(ASeed);
- uint BSeed = NextSeed(ASeed);
- lsr = BSeed >> 16;
- mod = lsr % 100;
- if (mod <= 34)
- {
- ASeed = BSeed;
- }
- }
- else
- {
- break;
- }
- } while (mod <= 34);
- }
- if ( n >= 10)
- {
- Console.WriteLine($"0x{Seed:X8} {n} times");
- writer.WriteLine($"0x{Seed:X8} {n} times");
- }
- }
- Console.WriteLine($"Final Seed 0x{Seed:X8}");
- writer.WriteLine($"Final Seed 0x{Seed:X8}");
- Console.WriteLine($"Generated {count} seeds. Output saved to {outputPath}");
- }
- }
- else
- {
- Console.WriteLine("Invalid Input for SEED Count.");
- }
- }
- else
- {
- Console.WriteLine("Invalid Input for Initial SEED.");
- }
- }
- static uint NextSeed(uint Seed)
- {
- ulong a = 1103515245;
- ulong b = 24691;
- ulong result = (a * Seed + b) & 0xFFFFFFFF;
- return (uint)result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement