I am trying to reproduce some Visual Basic code in python. I have a function which produces a fraction (double) and converts it to an integer as follows:
Dim random_int As Integer
Dim rounded_int As Integer
random_int = CInt(Math.Ceiling(Rnd() * n)) + 1
rounded_int = CInt(random_int/2)
CInt()
rounds double values to the nearest integer. However when the value is 0.5, this appears to be random; sometimes up, sometimes down. This makes the code difficult to test. In python(2.7), the number is always rounded in the same direction.
I could add or subtract a small number to the result (e.g. 0.1) but the original code should not changed.
Is this behaviour normal or can I control it in some way?