
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Generate Random Five Prime Numbers Between 100 to 150 in Python
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
Advertisements