+ 4

difference between randint and randrange

i dont understand what is the main difference in practice between random.randint and random randrange? with both i can choose the same interval, right?

9th Oct 2016, 8:27 PM
Benedek Máté Tóth
Benedek Máté Tóth - avatar
3 Respostas
+ 6
With randint(start,stop) you get an integer between start and stop. With randrange(start,stop,step) you can get an integer between start and stop by step eg: randint(2,7) = 2,3,4,5,6,7 randrange(0,10,2) = 0,2,4,6,8,10
9th Oct 2016, 10:06 PM
bryan freire
bryan freire - avatar
+ 1
oh, super. clear now! thanks.
10th Oct 2016, 4:29 PM
Benedek Máté Tóth
Benedek Máté Tóth - avatar
+ 1
1.randint() takes only 2 arguments Used when we know the start and end values. Syntax-randint(start,stop) Example import random random.randint(10) #invalid random.randint(1,10) #valid 2.randrange() can take 1,2 or 3 argument Used when we don't know both the limit Syntax -randrange(start,stop,steps) Example- import random random.randrange(5) random.randrange(1,9) random.randrange(1,10,2)
15th Jun 2019, 4:47 AM
nitesh pandey
nitesh pandey - avatar