'mechanism of 'int(random()*10)'

In python we can use int(random()*10) to import random interger, then mechanism of this is round the decimal? I wonder this because if what I think is happen, probability of 0 and 1 should be different,,



Solution 1:[1]

As you can read in the docs, int() truncates floating point numbers towards zero, it does not round them. Essentially, it just chops the decimal part off. So, int(9.999) returns 9, not 10.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 MattDMo