https://github.com/sudongcu/lcg_visualizer
A WPF application that visualizes the Linear Congruential Generator (LCG) algorithm.
https://github.com/sudongcu/lcg_visualizer
algorithms csharp lgc simulator wpf
Last synced: about 1 month ago
JSON representation
A WPF application that visualizes the Linear Congruential Generator (LCG) algorithm.
- Host: GitHub
- URL: https://github.com/sudongcu/lcg_visualizer
- Owner: sudongcu
- License: mit
- Created: 2025-11-07T13:32:19.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-11-25T03:00:08.000Z (7 months ago)
- Last Synced: 2025-11-28T12:55:37.807Z (7 months ago)
- Topics: algorithms, csharp, lgc, simulator, wpf
- Language: C#
- Homepage:
- Size: 24.4 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# LCG Visualizer
A WPF application that visualizes the Linear Congruential Generator (LCG) algorithm.
## 📋 Overview
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 value
- `a`: Multiplier
- `c`: Increment
- `m`: Modulus
This application visualizes the sequence generated by the LCG algorithm in a circular graph, allowing intuitive observation of cycle patterns.
## ✨ Key Features
- **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
## 🚀 Usage
### System Requirements
- .NET 10.0 or higher
- Windows OS
- WPF-supported environment
### Parameter Configuration
1. **m (Modulus)**: Range of numbers to generate (positive integer)
2. **a (Multiplier)**: Multiplier value
3. **c (Increment)**: Increment value
4. **seed**: Initial value
### Recommended Parameter Combinations
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)
#### Example Combinations:
```
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
```
### Controls
1. Enter desired parameter values in the top input fields
2. Click the ▶ button to start visualization
3. Use the X button to close the application
## 📊 Visualization Interpretation
### Screen Layout
- **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
### Result Analysis
- **Cycle Length**: Period of sequence repetition
- **Pre-cycle Length**: Length before cycle begins
- **Visual Patterns**: Geometric patterns appearing in the circular graph
## 🛠️ Tech Stack
- **Language**: C#
- **Framework**: .NET 10.0, WPF
- **UI**: XAML
- **Asynchronous Processing**: Task/async-await
## 📁 Project Structure
```
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
```
## 📚 Understanding LCG Algorithm
### Operating Principle
1. Start with initial seed value
2. Repeatedly apply the formula `(a × X_n + c) mod m`
3. Generated sequence eventually forms a cycle
4. Cycle length and pattern are determined by parameters
### Practical Applications
- Random number generation in game development
- Simulation and modeling
- Cryptographic applications (simple forms)
- Mathematical education and research
## 🔧 Build and Run
### Using Visual Studio:
1. Open the solution file (`.slnx`)
2. Press F5 for debug run or Ctrl+F5 for release run
### Using Command Line:
```bash
cd LCG_Visualizer
dotnet build
dotnet run
```

## 📄 License
This project is open source and licensed under the [MIT License](LICENSE).