0% found this document useful (0 votes)
4 views2 pages

python_exp8_sem4

The document outlines an experiment to generate unique random numbers using Python's random module. Key functions such as seed(), random(), randrange(), and randint() are explained, along with example outputs. The conclusion emphasizes the understanding of controlling and reproducing random numbers in Python.

Uploaded by

23224
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

python_exp8_sem4

The document outlines an experiment to generate unique random numbers using Python's random module. Key functions such as seed(), random(), randrange(), and randint() are explained, along with example outputs. The conclusion emphasizes the understanding of controlling and reproducing random numbers in Python.

Uploaded by

23224
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Experiment – 08

Aim: Write a program to generate a series of unique random number by using random
module.

Software Used: Spyder

Theory:

The random module in Python is used to generate random numbers. It provides various
functions to generate random integers, floating-point numbers, and unique values. Below are
some key functions of the random module:

1. random.seed(a)

• Initializes the random number generator with a seed value a.


• If the same seed is used, the sequence of random numbers remains the same.
• Useful for reproducibility in experiments.
2. random.random()

• Returns a random floating-point number between 0.0 and 1.0.


• Example: random.random() → 0.6745 (varies on each execution).
3. random.randrange(start, stop, step)

• Returns a random integer within a specified range, excluding the stop value.
• The step parameter allows selecting values at specific intervals.
• Example: random.randrange(10, 50, 5) → Possible outputs: 10, 15, 20, ..., 45.
4. random.randint(start, end)

• Returns a random integer between start and end (both inclusive).


• Example: random.randint(1, 100) → Random number between 1 and 100.

Source Code:
import random
random.seed(10)
print(random.random())
print(random.randrange(3,25,4))
print(random.randint(3, 9))

print("a series of unique random number :")


for i in range(10):
print(random.randint(i, i+10))
Output:

Conclusion:

In this experiment, I learned how Python's random module creates random numbers. Using
seed(), randrange(), random(), and randint(), I saw how numbers can be controlled and
repeated when needed.

You might also like