Created
May 8, 2018 06:16
-
-
Save ImSingee/5d3c4f6c7f1d119b4e37bcaeb7513aba to your computer and use it in GitHub Desktop.
取 [start, end) 间的随机数,保留 accuracy 位小数
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_random(start=0, end=1, accuracy=0): | |
rnd = random.random() # [0, 1) | |
rnd = (end - start) * rnd + start # [start, end) | |
if accuracy == 0: | |
return int(rnd) | |
else: | |
return round(rnd, accuracy) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment