Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
EeroEternal committed Dec 2, 2022
1 parent cd72b45 commit 29ea314
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/magicbag/mock/int.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 29ea314

Please sign in to comment.