Python3 Func Number Randrange
# Python3.x Python3 randrange() Function
[ Python3 Numbers](#)
* * *
## Description
The **randrange()** method returns a random number from a specified incrementing base set, with a default base value of 1.
* * *
## Syntax
Here is the syntax for the randrange() method:
import random random.randrange ([start,] stop [,step])
**Note:** randrange() cannot be accessed directly; you need to import the random module and then call the method through the random static object.
* * *
## Parameters
* start -- The starting value within the specified range, included in the range.
* stop -- The ending value within the specified range, not included in the range.
* step -- Specifies the increment base.
* * *
## Return Value
Returns a random item from the given range.
* * *
## Example
The following demonstrates examples of using the randrange() method:
## Example (Python 3.0+)
#!/usr/bin/python3#!/usr/bin/python3 import random# Select an odd number from 1-100 print("randrange(1,100, 2) : ", random.randrange(1, 100, 2))# Select a random number from 0-99 print("randrange(100) : ", random.randrange(100))
The output of the above example after running is:
randrange(1,100, 2) : 97 randrange(100) : 42
[ Python3 Numbers](#)
YouTip