LAB 01
Computer Generation of Random Numbers
(Python Version)
Objective:
The objective of this lab is to understand how to generate different types of random
numbers using Python and to study their properties for use in simulations and
statistical modeling.
Software Required:
PyCharm (any version)
Python
Libraries:
Numpy
Matplotlib
1. Generating Uniform Random Numbers
Explanation: This program generates uniform random numbers between 0 and 1,
where each number has an equal probability of occurrence. The generated values
are plotted to visualize their randomness.
Python Code:
Code Output:
Exercise I: Generate Random Numbers Between 5 and 10
Explanation: This program generates uniform random numbers and shifts their
range so that all generated values lie between 5 and 10.
Python Code:
Code Output:
Exercise II: Histogram of Uniform Random Numbers
Explanation: This program generates a large number of uniform random values and
displays their distribution using a histogram.
Python Code:
Code Output:
2. Generating Normally Distributed
(Gaussian) Random Numbers
Explanation: This program generates random numbers that follow a normal
(Gaussian) distribution with mean zero and unit standard deviation and plots the
values.
Python Code:
Exercise I: Histogram of Gaussian Random Numbers
Explanation: This program displays the distribution of Gaussian random numbers
using a histogram to observe the bell-shaped curve.
Python Code:
Code Output:
Exercise II: Gaussian Random Numbers with Custom Mean
and Standard Deviation
Explanation: This program modifies the mean and standard deviation to generate
Gaussian random numbers centered around a specified mean.
Python Code:
Code Output:
3. Generating Exponentially Distributed
Random Numbers
Explanation: This program generates exponentially distributed random numbers,
which are commonly used to model waiting times, and plots the values.
Python Code:
Code Output:
Exercise: Histogram of Exponential Random Numbers (λ =
0.5)
Explanation: This program generates exponential random numbers using a specified
rate parameter and visualizes their distribution with a histogram.
Python Code:
Code Output:
4. Random Integer Generation
Explanation: This program generates random integer values within a defined range.
Python Code:
Code Output:
Exercise: 5×5 Matrix of Random Integers
Explanation: This program generates a two-dimensional matrix of random integers
within the specified limits.
Python Code:
Code Output:
5. Seeding Random Numbers
(Reproducibility)
Explanation: This program uses a fixed seed value to ensure that the same sequence
of random numbers is generated every time the program is executed.
Python Code:
Code Output:
Exercise: Verification Using Same Seed
Explanation: This program demonstrates that using the same seed value results in
identical random numbers, ensuring reproducibility of results.
Python Code:
Code Output:
Conclusion:
In this lab, uniform, normal, exponential, and integer random numbers were
generated using Python. Graphs and histograms were used to visualize different
distributions, and random seeds were applied to ensure reproducibility of results.