A WPF application that visualizes the Linear Congruential Generator (LCG) algorithm.
LCG (Linear Congruential Generator) is one of the pseudorandom number generation algorithms that uses the following formula:
X_{n+1} = (a × X_n + c) mod m
Where:
X_n: Current valuea: Multiplierc: Incrementm: Modulus
This application visualizes the sequence generated by the LCG algorithm in a circular graph, allowing intuitive observation of cycle patterns.
- Real-time Visualization: Animated display of LCG sequence generation process
- Cycle Detection: Automatic detection of sequence periods and cycle starting points
- Parameter Adjustment: Free modification of m, a, c, seed values to observe various patterns
- Fullscreen Mode: Optimized visualization experience
- Color Gradients: Color coding for easy distinction between steps
- .NET 10.0 or higher
- Windows OS
- WPF-supported environment
- m (Modulus): Range of numbers to generate (positive integer)
- a (Multiplier): Multiplier value
- c (Increment): Increment value
- seed: Initial value
Parameter selection guide for good periods:
- m: Desired random number range
- a: (a-1) must be divisible by all prime factors of m
- c: Value coprime with m (1 recommended)
m=9, a=4, c=1, seed=0 (default)
m=16, a=5, c=1, seed=0
m=32, a=5, c=1, seed=0
- Enter desired parameter values in the top input fields
- Click the ▶ button to start visualization
- Use the X button to close the application
- Circular Arrangement: Numbers from 0 to m-1 arranged clockwise
- Arrows: Indicate transitions between each step
- Colors: Gradient colors applied for each step
- Red Circle: Marks the cycle starting point
- Cycle Length: Period of sequence repetition
- Pre-cycle Length: Length before cycle begins
- Visual Patterns: Geometric patterns appearing in the circular graph
- Language: C#
- Framework: .NET 10.0, WPF
- UI: XAML
- Asynchronous Processing: Task/async-await
LCG_Visualizer/
├── MainWindow.xaml # UI Layout
├── MainWindow.xaml.cs # Main logic and visualization
├── App.xaml # Application configuration
├── App.xaml.cs # Application entry point
└── LCG_Visualizer.csproj # Project file
- Start with initial seed value
- Repeatedly apply the formula
(a × X_n + c) mod m - Generated sequence eventually forms a cycle
- Cycle length and pattern are determined by parameters
- Random number generation in game development
- Simulation and modeling
- Cryptographic applications (simple forms)
- Mathematical education and research
- Open the solution file (
.slnx) - Press F5 for debug run or Ctrl+F5 for release run
cd LCG_Visualizer
dotnet build
dotnet runThis project is open source and licensed under the MIT License.
