You are on page 1of 3

Class-XII Computer Science

In-Built Functions and Library modules


1. Math Functions
https://www.youtube.com/watch?v=EkYrfV7M1ks
https://www.tutorialspoint.com/python-mathematical-functions
2. Random Functions
This module implements pseudo-random number generators for various distributions.
It is used for generating secure passwords, unique id’s, cryptography and in developing quiz
and games. Some common random functions that we are going to learn here are as follows:
We need to import the random module in our program before we use these functions. Use
the following statement to import the random module in your code.

 random() is the most basic function of the random module.


 Almost all functions of the random module depend on the basic function random().
 random() return the next random floating-point number in the range [0.0, 1.0).

 random.randint(): Returns a random integer between the specified integers. This function


returns a random integer within a range. This function takes two parameters. Both are
mandatory. For example, random.randint(0, 100) will return any random number between 0 to
100.
 The randint(start, stop) includes both start and stop numbers while generating random
integer. It will generate a random number from the inclusive range.
random.randrange()

This function returns a randomly selected integer from range(start, stop, step). This function takes
three parameters. Out of three parameters, two parameters are optional. i.e., start and step are the
optional parameters.

 The start argument is the starting number in a random range. i.e., lower limit. The default
value of start is 0 if not specified.
 The stop argument is the last number in a random range. the stop argument is the upper
limit.
 The step is a difference between each number in the sequence. The step is optional
parameters. The default value of the step is 1 if not specified.

random.choice(): Returns a randomly selected element from a non-


empty sequence. An empty sequence as argument raises an IndexError.
random.uniform()

The uniform() method returns a random floating number between the two specified


numbers (both included).

https://www.youtube.com/watch?v=KzqSDvzOFNA
https://www.youtube.com/watch?v=S66yKRtbELM

You might also like