当前位置: 首页>>代码示例>>Python>>正文


Python Commons.get_random_int方法代码示例

本文整理汇总了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
开发者ID:joshcoales,项目名称:Hallo,代码行数:16,代码来源:Random.py

示例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] + '"'
开发者ID:,项目名称:,代码行数:9,代码来源:

示例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)
开发者ID:joshcoales,项目名称:Hallo,代码行数:14,代码来源:testCommons.py

示例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)
开发者ID:joshcoales,项目名称:Hallo,代码行数:14,代码来源:Random.py

示例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)
开发者ID:joshcoales,项目名称:Hallo,代码行数:6,代码来源:Random.py


注:本文中的inc.Commons.Commons.get_random_int方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。