Introduction

Setup

Operators

variable

String

Number

Dtype & Comment

Lists

Tuples

Sets

Dictionaries

if else statement

For Loop

While Loop

iterator & iterable

Pre-Built functions

Function

Decorators

Generators

Types of errors

Exceptions Handling

OOP

Regular expression

Create module

OS module

Date module

Random module

Math

Statistics module

Exercise 1

Exercise 2

Exercise 3

Learn Data Structure & Algorithm

Learn Numpy

Learn Pandas

Learn Matplotlib

Learn Seaborn

Learn Statistics

Learn Math

Learn MATLAB

Learn Machine learning

Learn Github

Learn OpenCV

Learn Deep Learning

Learn MySQL

Learn MongoDB

Learn Web scraping

Learn Excel

Learn Power BI

Learn Tableau

Learn Docker

Learn Hadoop

Python random module

What is random module?

Random module is python built-in module. By this module we can generate random numbers

Random module methods:


Methods Description
setstate() This method restores the internal state of the random number generator
random() This method returns a random float number between 0 and 1
getrandbits() This method returns a number representing the random bits
seed() This method initialize the random number generator
gauss() This method returns a random float number based on the Gaussian distribution
randrange() This method returns a random number between the given range
lognormvariate() This method returns a random float number based on a log-normal distribution
sample() This method returns a given sample of a sequence
gammavariate() This method returns a random float number based on the Gamma distribution
normalvariate() This method returns a random float number based on the normal distribution
getstate() This method returns the current internal state of the random number generator
shuffle() This method takes a sequence and returns the sequence in a random order
betavariate() This method returns a random float number between 0 and 1 based on the Beta distribution (used in statistics)
randint() This method returns a random number between the given range
choices() This method returns a list with a random selection from the given sequence
expovariate() This method returns a random float number based on the Exponential distribution
vonmisesvariate() This method a random float number based on the von Mises distribution
triangular() This method returns a random float number between two given parameters. Here you can also set a mode parameter to specify the midpoint between the two other parameters
uniform() This method returns a random float number between two given parameters
paretovariate() This method returns a random float number based on the Pareto distribution
choice() This method returns a random element from the given sequence

Example:1
Input
import random

random.seed(50)
print(random.random())
Output
0.4975365687586023
Example:2
Input
import random

print(random.randint(5, 19))
Output
12
Example:3
Input
import random

ml = ["car", "bike", "motor"]
random.shuffle(ml)

print(ml)
Output
['motor', 'bike', 'car']

CodersAim is created for learning and training a self learner to become a professional from beginner. While using CodersAim, you agree to have read and accepted our terms of use, privacy policy, Contact Us

© Copyright All rights reserved www.CodersAim.com. Developed by CodersAim.