本文整理汇总了Python中inc.Commons.Commons.get_random_int方法的典型用法代码示例。如果您正苦于以下问题:Python Commons.get_random_int方法的具体用法?Python Commons.get_random_int怎么用?Python Commons.get_random_int使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类inc.Commons.Commons
的用法示例。
在下文中一共展示了Commons.get_random_int方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_dice_format
# 需要导入模块: from inc.Commons import Commons [as 别名]
# 或者: from inc.Commons.Commons import get_random_int [as 别名]
def run_dice_format(self, num_dice, num_sides):
"""Rolls numDice number of dice, each with numSides number of sides"""
if num_dice == 0 or num_dice > 100:
return "Invalid number of dice."
if num_sides == 0 or num_sides > 1000000:
return "Invalid number of sides."
if num_dice == 1:
rand = Commons.get_random_int(1, num_sides)[0]
return "I roll {}!!!".format(rand)
else:
dice_rolls = Commons.get_random_int(1, num_sides, num_dice)
output_string = "I roll {}. The total is {}.".format(", ".join([str(x) for x in dice_rolls]),
sum(dice_rolls))
return output_string
示例2: run
# 需要导入模块: from inc.Commons import Commons [as 别名]
# 或者: from inc.Commons.Commons import get_random_int [as 别名]
def run(self, line, user_obj, destination_obj=None):
"""WH40K Thought for the day. Format: thought_for_the_day"""
thought_list = Commons.read_file_to_list('store/WH40K_ToTD2.txt')
rand = Commons.get_random_int(0, len(thought_list) - 1)[0]
if thought_list[rand][-1] not in ['.', '!', '?']:
thought_list[rand] += "."
return '"' + thought_list[rand] + '"'
示例3: test_get_random_int
# 需要导入模块: from inc.Commons import Commons [as 别名]
# 或者: from inc.Commons.Commons import get_random_int [as 别名]
def test_get_random_int(self):
for count in range(1, 3):
for max_int in range(2, 10):
for min_int in range(1, 5):
if min_int > max_int:
continue
rand_list = Commons.get_random_int(min_int, max_int, count)
assert len(rand_list) == count, "Random integer list is the wrong length. " + str(rand_list) + \
" not " + str(count) + " elements"
for rand in rand_list:
assert rand >= min_int, "Random integer was too small. " + str(rand) + " < " + str(min_int)
assert rand <= max_int, "Random integer was too big. " + str(rand) + " > " + str(max_int)
示例4: run
# 需要导入模块: from inc.Commons import Commons [as 别名]
# 或者: from inc.Commons.Commons import get_random_int [as 别名]
def run(self, event):
rgb_list = Commons.get_random_int(0, 255, 3)
hex_code = "{}{}{}".format(hex(rgb_list[0])[2:].zfill(2),
hex(rgb_list[1])[2:].zfill(2),
hex(rgb_list[2])[2:].zfill(2)).upper()
url = "https://www.thecolorapi.com/id?hex={}".format(hex_code)
human_url = "{}&format=html".format(url)
colour_data = Commons.load_url_json(url)
colour_name = colour_data["name"]["value"]
output = "Randomly chosen colour is: {} #{} or rgb({},{},{}) {}".format(colour_name, hex_code, rgb_list[0],
rgb_list[1], rgb_list[2], human_url)
return event.create_response(output)
示例5: run_range_format
# 需要导入模块: from inc.Commons import Commons [as 别名]
# 或者: from inc.Commons.Commons import get_random_int [as 别名]
def run_range_format(self, range_min, range_max):
"""Generates a random number between rangeMin and rangeMax"""
rand = Commons.get_random_int(range_min, range_max)[0]
return "I roll {}!!!".format(rand)