Why this code behaves abnormally when using numpy? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why this code behaves abnormally when using numpy?

So in this code I used the randint function from the built-in random module. But when I use the randint function from numpy's random module it shows some unexpected results. Why does this happen? You can try this by changing the first line with: from numpy.random import randint https://code.sololearn.com/croZDPmy580X/?ref=app

4th Feb 2020, 2:15 PM
Ishmam
Ishmam - avatar
2 Answers
+ 3
random.randint(a, b) returns a number with the upper bound inclusive (a <= x <= b) numpy.random.randint(a, b) returns a number with upper bound exclusive (a <= x < b) It's not abnormal, they are just different.
4th Feb 2020, 2:51 PM
Tibor Santa
Tibor Santa - avatar
+ 3
Tibor Santa Hm.. That's what I was thinking. Thanks for the confirmation. 😄
4th Feb 2020, 3:01 PM
Ishmam
Ishmam - avatar