
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
- Python Advanced Tutorial
- Python - Classes/Objects
- Python - Reg Expressions
- Python - CGI Programming
- Python - Database Access
- Python - Networking
- Python - Sending Email
- Python - Multithreading
- Python - XML Processing
- Python - GUI Programming
- Python - Further Extensions
- Python Useful Resources
- Python - Questions and Answers
- Python - Quick Guide
- Python - Tools/Utilities
- Python - Useful Resources
- Python - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Number randrange() Method
Description
Python number method randrange() returns a randomly selected element from range(start, stop, step).
Syntax
Following is the syntax for randrange() method −
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
start − Start point of the range. This would be included in the range.
stop − Stop point of the range. This would be excluded from the range.
step − Steps to be added in a number to decide a random number.
Return Value
This method returns a random item from the given range
Example
The following example shows the usage of randrange() method.
#!/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)
When we run above program, it produces following result −
randrange(100, 1000, 2) : 976 randrange(100, 1000, 3) : 520
python_numbers.htm
Advertisements