How to randomly select element from range in Python?

PythonServer Side ProgrammingProgramming

The randrange() function from random module returns a randomly selected number from range of numbers. The format of function is as follows −

randrange(start, stop, step)

start is 0 by default and step is 1 by default. Following are some examples of randrange() unction −

>>> import random
>>> x=random.randrange(10,20,2) #even numbers between 10-20
>>> x
16
>>> x=random.randrange(1,100,2) #odd numbers between 0-100
>>> x
55
raja
Published on 05-Mar-2018 10:36:41
Advertisements