Skip to content

rand

round_number(num)

Round a number float depeding on the uniform distribution, the number can be round by the ceil or floor

Parameters:

Name Type Description Default
num int

Number to round.

required

Returns:

Type Description
float

Rounded number.

Source code in rivertext/utils/rand.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
def round_number(num: int) -> float:

    """Round a number float depeding on the uniform distribution,
        the number can be round by the ceil or floor

    Args:
        num: Number to round.

    Returns:
        Rounded number.
    """
    c = ceil(num)
    f = floor(num)
    uni = int(np.random.uniform(0.0, 1.0))
    if uni < (num - f):
        return c
    else:
        return f