# Write a program in Python to generate any random five prime numbers between 100 to 150 in a Series

PythonPandasServer Side ProgrammingProgramming

## Solution

To solve this, we will follow the steps given below −

• Define an empty list

• Create a for loop and set range from 100 to 150

• Set another for loop to access the values from 2 to range of values and find the factors, if nothing is found then add to the list. It is defined below,

for i in range(100,150):
for j in range(2, i):
if(i % j == 0):
break
else:
l.append(i)
• Set random sample value as 5 and assign into the list then finally create a Series.

data = rand.sample(l,5)
rand_series = pd.Series(data)

### Example

Let us see the following implementation to get a better understanding.

import pandas as pd
import random as rand
l = []
for i in range(100,150):
for j in range(2, i):
if(i % j == 0):
break
else:
l.append(i)
data = rand.sample(l,5)
rand_series = pd.Series(data)
print(rand_series)

### Output

0    109
1    149
2    107
3    101
4    131