Copyright © tutorialspoint.com

Python Number randrange() Function

previous next


Description:

This function returns a randomly selected element from range(start, stop, step)

Syntax:

randrange ([start,] stop [,step])

Note: This function is not accessible directly so we need to import random module and then we need to call this function using random static object.

Parameters:

Here is the detail of parameters:

Return Value:

A random item from the given range

Example:

#!/usr/bin/python
import random

# Select an even number in 100 <= number < 1000
print "randrange(100, 1000, 2) : ", random.randrange(100, 1000, 2)

# Select another number in 100 <= number < 1000
print "randrange(100, 1000, 3) : ", random.randrange(100, 1000, 3)

This will produce following result:

randrange(100, 1000, 2) :  976
randrange(100, 1000, 3) :  520

previous next

Copyright © tutorialspoint.com