What does `random.randint()` do?

Am I the only one who thinks there’s a chunk of info missing like what does random.randint() does and how to use it?

2 Likes

The name randint suggests this method will return an integer within some specified boundaries.

y = random.randint(1, 10) =>  { y | 1 <= y <= 10; y is int }

Note that this does not exclude the upper boundary. Both boundaries are inclusive. y above will be an integer from the above described inequality.

4 Likes

could you briefly explain this code please ? what and how is it doing ?

It’s actually not code, but mathematics describing the solution set, y.

{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

y, such that 1 is less than or equal to y and y is less than or equal to 10; y belongs to the set of Integers.

ok, but shouldn’t Y be greater than or equal to 1 since the range is 1 to 10 ?

Inequalities are always written with the arrows pointing the same direction.

1 Like

I’m used to see >= this than <= this and that’s why I had mistaken.

1 Like