namofure

AIプログラミング①

Dec 24th, 2025
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.47 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.                         Console.WriteLine($"Count:{count}, Seed:{Seed:X8}");
  22.                         writer.WriteLine($"Count:{count}, Seed:{Seed:X8}");
  23.                     }
  24.                     Console.WriteLine($"Generated {count} seeds. Output saved to {outputPath}");      
  25.                 }
  26.             }
  27.             else { Console.WriteLine("Invalid Input for SEED Count."); }
  28.         }
  29.         else { Console.WriteLine("Invalid Input for Initial SEED."); }
  30.     }
  31.    
  32.     static uint NextSeed(uint Seed)
  33.     {
  34.         uint a = 1103515245;
  35.         uint b = 12345;
  36.         return (a * Seed + b);
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment