namofure

AIプログラミング②

Dec 24th, 2025 (edited)
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.29 KB | Source Code | 0 0
  1. class LCG
  2. {
  3.     static void Main()
  4.     {
  5.         Console.Write("Enter Initial SEED : 0x");   // 初期SEED入力
  6.         if (uint.TryParse(Console.ReadLine(), System.Globalization.NumberStyles.HexNumber, null, out uint Seed))
  7.         {
  8.             Console.Write("Enter SEED Count :");
  9.             if (int.TryParse(Console.ReadLine(), out int count) && count > 0)
  10.             {
  11.                 Console.Write("Enter File Name :");
  12.                 string outputPath = Console.ReadLine();
  13.                 if (!outputPath.EndsWith(".txt", StringComparison.OrdinalIgnoreCase))
  14.                 {
  15.                     outputPath += ".txt";
  16.                 }
  17.                 using (StreamWriter writer = new(outputPath))
  18.                 {
  19.                     for (int i = 1; i < count; i++, Seed = NextSeed(Seed))
  20.                     {
  21.                         uint lsr = (Seed >> 16);
  22.                         uint Scout = lsr % 1000;
  23.  
  24.                         DateTime baseDate = new DateTime(2000, 1, 1, 0, 0, 0);
  25.                         TimeSpan elapsedTime = TimeSpan.FromSeconds(Seed);
  26.                         DateTime resultDate = baseDate.Add(elapsedTime);
  27.  
  28.                         if (Scout == 0)
  29.                         {
  30.                             Console.WriteLine($"0x{Seed:X8} [{resultDate.ToString("yyyy/MM/dd HH:mm:ss")}] Scout!");
  31.                             writer.WriteLine($"0x{Seed:X8} [{resultDate.ToString("yyyy/MM/dd HH:mm:ss")}] Scout!");
  32.                         }
  33.                         else
  34.                         {
  35.                             Console.WriteLine($"0x{Seed:X8} [{resultDate.ToString("yyyy/MM/dd HH:mm:ss")}] {Scout / 10:d2}.{Scout % 10}%");
  36.                             writer.WriteLine($"0x{Seed:X8} [{resultDate.ToString("yyyy/MM/dd HH:mm:ss")}] {Scout / 10:d2}.{Scout % 10}%");
  37.                         }
  38.                     }
  39.                     Console.WriteLine($"Generated {count} seeds. Output saved to {outputPath}");
  40.                 }
  41.             }
  42.             else { Console.WriteLine("Invalid Input for SEED Count."); }
  43.         }
  44.         else { Console.WriteLine("Invalid Input for Initial SEED."); }
  45.     }
  46.     static uint NextSeed(uint Seed)
  47.     {
  48.         uint a = 1103515245;
  49.         uint b = 12345;
  50.         return (a * Seed + b);
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment