PBL 2025–26 · BVDUCOE, Pune

Probability Simulator
& Analyzer

ANIMESH PATTNAIK · Electronics & Telecommunication Engineering · Interactive Code Viewer

Python 3.x
📦 random · matplotlib
📁 PBL.py
🎓 Probability & Statistics
00

Project Overview

🎲
Simulations
Coin Toss + Dice Roll
📊
Output
Matplotlib Bar Charts
Speed
< 0.5s for N=100,000
📐
Algorithm
Mersenne Twister PRNG
01

Source Repository

Open Source · Public Repository
Full project on
GitHub

The complete source code, commit history, and documentation for the Probability Simulator & Analyzer lives here. Clone it, fork it, or star it — it's all yours.

PBL 2025–26
Solo Project
Python · MIT
BVDUCOE, Pune
Animesh0711 / Probability_Simulator_Analyzer
02

Complete Source Code — PBL.py

Python · PBL.py
1# ═══════════════════════════════════════════════════════════════
2# Probability Simulator & Analyzer
3# Author : Animesh Pattnaik | BVDUCOE, Pune | PBL 2025-26
4# ═══════════════════════════════════════════════════════════════
5
6import random
7import matplotlib.pyplot as plt
8
9n = int(input("Enter number of trials: "))
10
11# ── COIN TOSS ──────────────────────────────────────────────────
12heads = 0
13tails = 0
14
15for i in range(n):
16 toss = random.randint(0, 1)
17 if toss == 1:
18 heads += 1
19 else:
20 tails += 1
21
22print("Heads =", heads)
23print("Tails =", tails)
24
25plt.figure()
26plt.bar(["Heads", "Tails"], [heads, tails])
27plt.xlabel("Outcome")
28plt.ylabel("Count")
29plt.title("Coin Toss Simulation")
30plt.show()
31
32# ── DICE ROLL ──────────────────────────────────────────────────
33dice = [0, 0, 0, 0, 0, 0]
34
35for i in range(n):
36 value = random.randint(1, 6)
37 dice[value - 1] += 1
38
39print("Dice results:", dice)
40
41plt.figure()
42plt.bar([1, 2, 3, 4, 5, 6], dice)
43plt.xlabel("Dice Number")
44plt.ylabel("Frequency")
45plt.title("Dice Roll Simulation")
46plt.show()
03

Coin Toss Simulation Kernel

Python · coin_toss
1# Coin toss — Bernoulli trial P(H)=0.5
2heads, tails = 0, 0
3
4for i in range(n):
5 toss = random.randint(0, 1) # 0=Tails 1=Heads
6 if toss == 1: heads += 1
7 else: tails += 1
8
9print("Heads =", heads)
10print("Tails =", tails)
11plt.bar(["Heads", "Tails"], [heads, tails])
12plt.title("Coin Toss Simulation"); plt.show()
04

Dice Roll Simulation Kernel

Python · dice_roll
1# Dice roll — Discrete Uniform U{1..6}
2dice = [0] * 6
3
4for i in range(n):
5 value = random.randint(1, 6) # face 1–6
6 dice[value - 1] += 1
7
8print("Dice results:", dice)
9plt.bar([1,2,3,4,5,6], dice)
10plt.title("Dice Roll Simulation"); plt.show()
05

Terminal Output — N = 1000

bash · PBL.py output
$ python3 PBL.py
Enter number of trials: 1000
--- Coin Toss Results ---
Heads = 497
Tails = 503
--- Dice Roll Results ---
Dice results: [168, 162, 171, 163, 169, 167]
✓ Process exited with code 0 · runtime: 0.23s
06

How To Run

bash · setup & run
1# Install dependency (one-time)
2pip install matplotlib
3
4# Run the simulator
5python3 PBL.py
6
7# Enter when prompted — try these values:
8# 10 → high variance, fun to observe
9# 1000 → clear convergence visible
10# 100000 → near-perfect theoretical match