Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Randomly choose a number in a specific range with a specific multiple in python

Tags:

python

random

I have the following numbers:

100, 200, 300, 400 ... 20000

And I would like to pick a random number within that range. Again, that range is defined as 100:100:20000. Furthermore, by saying 'within that range', I don't mean randomly picking a number from 100->20000, such as 105. I mean randomly choosing a number from the list of numbers available, and that list is defined as 100:100:20000.

How would I do that in Python?

like image 900
Amit Avatar asked Sep 14 '11 17:09

Amit


1 Answers

Use random.randrange :

random.randrange(100, 20001, 100)
like image 85
mouad Avatar answered Oct 19 '22 13:10

mouad