Skip to content

sudongcu/LCG_Visualizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

cd LCG_Visualizer
dotnet build
dotnet run

lcg

📄 License

This project is open source and licensed under the MIT License.

About

A WPF application that visualizes the Linear Congruential Generator (LCG) algorithm.

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages