Curriculum
Course: NumPy
Login

Curriculum

NumPy

Text lesson

Random Intro

What is a Random Number?

A random number does not necessarily imply a different value each time; rather, random refers to something that cannot be predicted logically.

Pseudo Random and True Random.

Computers run on programs that consist of defined instructions, requiring an algorithm to generate random numbers. Since these numbers can be predicted, they are considered pseudo-random.

To create truly random numbers, external sources of randomness, such as keystrokes, mouse movements, or network data, are needed. Truly random numbers are mainly used for security (e.g., encryption keys) or applications that rely on randomness (e.g., digital roulette wheels). This tutorial will focus on using pseudo-random numbers.

Generate Random Number

NumPy provides the random module for working with random numbers.

Example

Create a random integer between 0 and 100:

from numpy import random

x = random.randint(100)

print(x)

Generate Random Float

The rand() method from the random module returns a random float between 0 and 1.

Example

Create a random float between 0 and 1:

from numpy import random

x = random.rand()

print(x)