Skip to main content

Diving Into Modules - Random Module

 

Source: Cyndie Meyer

Random Module: This is an inbuilt module we get in the Python ecosystem and is used for bringing some variability in the program whenever required. This module is full of a ton of functions that are continuously in use in real life.

Note! : To use the functions in this module, you have to import this module at least once. The syntax for this operation is given below.

Syntax:

import random

Some Functions in Random Module

random(): This function returns a float value between 0 and 1.

Syntax:
x = random.random()
print(x)

randrange(): This function returns a random number between any given range (exclusive of the last number).

Syntax:
y = random.ranrange(2,7)
print(y)

randint(): This function returns a random number between any given range (inclusive of the last number).

Syntax:
z = random.randint(2,7)
print(z)

More functions will be continued in a later blog post...

©SGPython

Comments

Popular posts from this blog

Our view towards Python (as a programming language)

  Python - The language of the future Introduction When we hear the term programming language, we usually talk about high-level programming language which are those programming language having a lucid (or easy-to-read) syntax and are later converted to low-level language (binary) , which is understandable by the computer.  Programming language has always been an area of interest over the passing years since the very early days of ' Fortran ' (created by John Backus at  IBM ). To this day, dozens of programming language has been created by different 'Computer Scientists' around the world. What is Python? What is Python? Many of you will describe a large scary snake 🐍, which isn't actually wrong 😅. But here we are talking about a programming language. Similarly, Python is also a high-level and interepreted programming language created by  Guido van Rossum in the late 1980s . It was first released in 1991 as a successor to ABC Programming language . It known fo...

Factorial of a Number by a User-Defined Function (PCTS)

 Factorial of a Number There are a number of ways to find the factorial of a number (obviously, it going to a whole number 😆). Out of all of them today, I'm going to show you the user-defined code I created to find the factorial of any whole number. Trust me, it's cool 😎 just give it a try...

For Loops

 The for loop By  polygraphus  on  shutterstock Def: The for loop is also known as the counting loop and is designed to process the items of any sequence, such as a list or a string, one by one. General form of for loop: The general form of the for loop is given below:      for <variable> in <sequence>:          statements to repeat