diff --git a/src/magicbag/mock/int.py b/src/magicbag/mock/int.py index e680c01..a17a61b 100644 --- a/src/magicbag/mock/int.py +++ b/src/magicbag/mock/int.py @@ -3,12 +3,24 @@ import random -def random_fixed_int(length): +def random_fixed_int(length, negative=False): """Generate fix length random int. Args: fix_length (int): fix length + negetive (bool): if True, can generate negative int Return: (int): random int """ - return random.randint(10 ** (length - 1), 10**length - 1) + # generate positive fixed length int + positive = random.randint(10 ** (length - 1), 10**length - 1) + + # if negative is True, return positive or negative int + if negative: + if random.choice([True, False]): + return positive + + return -positive + + # not negative return positive + return positive