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


Python random.html方法代码示例

本文整理汇总了Python中random.html方法的典型用法代码示例。如果您正苦于以下问题:Python random.html方法的具体用法?Python random.html怎么用?Python random.html使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在random的用法示例。


在下文中一共展示了random.html方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import random [as 别名]
# 或者: from random import html [as 别名]
def __init__(self, min_included: float, max_included: float, null_default_value=None):
        """
        Create a random uniform distribution.
        A random float between the two values somehow inclusively will be returned.

        :param min_included: minimum integer, included.
        :type min_included: float
        :param max_included: maximum integer, might be included - for more info, see `examples <https://docs.python.org/2/library/random.html#random.uniform>`__
        :type max_included: float
        :param null_default_value: null default value for distribution. if None, take the min_included
        :type null_default_value: int
        """
        if null_default_value is None:
            HyperparameterDistribution.__init__(self, min_included)
        else:
            HyperparameterDistribution.__init__(self, null_default_value)

        self.min_included: float = min_included
        self.max_included: float = max_included 
开发者ID:Neuraxio,项目名称:Neuraxle,代码行数:21,代码来源:distributions.py

示例2: sign

# 需要导入模块: import random [as 别名]
# 或者: from random import html [as 别名]
def sign(username, private_key, generate_nonce=None, iat=None, algorithm=DEFAULT_ALGORITHM):
    """
    Create a signed JWT using the given username and RSA private key.

    :param username: Username (string) to authenticate as on the remote system.
    :param private_key: Private key to use to sign the JWT claim.
    :param generate_nonce: Optional. Callable to use to generate a new nonce. Defaults to
        `random.random <https://docs.python.org/3/library/random.html#random.random>`_.
    :param iat: Optional. Timestamp to include in the JWT claim. Defaults to
        `time.time <https://docs.python.org/3/library/time.html#time.time>`_.
    :param algorithm: Optional. Algorithm to use to sign the JWT claim. Default to ``RS512``.
        See `pyjwt.readthedocs.io <https://pyjwt.readthedocs.io/en/latest/algorithms.html>`_ for other possible algorithms.
    :return: JWT claim as a string.
    """
    iat = iat if iat else time.time()
    if not generate_nonce:
        generate_nonce = lambda username, iat: random.random()  # NOQA

    token_data = {
        'username': username,
        'time': iat,
        'nonce': generate_nonce(username, iat),
    }

    token = jwt.encode(token_data, private_key, algorithm=algorithm)
    return token 
开发者ID:crgwbr,项目名称:asymmetric-jwt-auth,代码行数:28,代码来源:token.py

示例3: get_font_file

# 需要导入模块: import random [as 别名]
# 或者: from random import html [as 别名]
def get_font_file(client, channel_id):
    # first get the font messages
    font_file_message_s = await client.get_messages(
        entity=channel_id,
        filter=InputMessagesFilterDocument,
        # this might cause FLOOD WAIT,
        # if used too many times
        limit=None
    )
    # get a random font from the list of fonts
    # https://docs.python.org/3/library/random.html#random.choice
    font_file_message = random.choice(font_file_message_s)
    # download and return the file path
    return await client.download_media(font_file_message) 
开发者ID:mkaraniya,项目名称:BotHub,代码行数:16,代码来源:sticklet_un.py

示例4: generate_key

# 需要导入模块: import random [as 别名]
# 或者: from random import html [as 别名]
def generate_key(key_length=64):
    """Secret key generator.

    The quality of randomness depends on operating system support,
    see http://docs.python.org/library/random.html#random.SystemRandom.
    """
    if hasattr(random, 'SystemRandom'):
        choice = random.SystemRandom().choice
    else:
        choice = random.choice
    return ''.join(map(lambda x: choice(string.digits + string.ascii_letters),
                   range(key_length))) 
开发者ID:CiscoSystems,项目名称:avos,代码行数:14,代码来源:secret_key.py

示例5: create_nonce

# 需要导入模块: import random [as 别名]
# 或者: from random import html [as 别名]
def create_nonce():
    x = len(NONCE_CHARS)

    # Class that uses the os.urandom() function for generating random numbers.
    # https://docs.python.org/2/library/random.html#random.SystemRandom
    randrange = random.SystemRandom().randrange

    return ''.join([NONCE_CHARS[randrange(x)] for _ in range(NONCE_LENGTH)]) 
开发者ID:scitran,项目名称:core,代码行数:10,代码来源:util.py

示例6: get_random_value

# 需要导入模块: import random [as 别名]
# 或者: from random import html [as 别名]
def get_random_value(config: Dict[Any, Any]):
    """
    Executes function from https://docs.python.org/3/library/random.html
    :param config: Config that contains type "get_random_value" with 'func' and 'args'
    :return:
    """
    config_dict = config
    if config_dict["type"] != "random":
        raise ValueError("Config with type {0} is not valid for this function".format(config_dict["type"]))

    func_str = config_dict["func"]
    func_args = dict(config_dict["args"])

    return_first = False
    if func_str.endswith("[0]"):
        return_first = True
        func_str = func_str[:-3]

    allowed_funcs = {
        "random.randint": random.randint,
        "randint": random.randint,
        "random.uniform": random.uniform,
        "uniform": random.uniform,
        "random.randrange": random.randrange,
        "randrange": random.randrange,
        "random.shuffle": random.shuffle,
        "shuffle": random.shuffle,
        "random.choice": random.choice,
        "choice": random.choice,
        "random.choices": random.choices,
        "choices": random.choices,
    }

    if not func_str in allowed_funcs:
        raise ValueError("Wrong function type {0}. The following types are allowed: {1}".format(func_str, ", ".join(sorted(allowed_funcs.keys()))))

    func = allowed_funcs[func_str]

    result_value = func(**func_args)
    if return_first:
        result_value = result_value[0]

    return result_value 
开发者ID:allenai,项目名称:OpenBookQA,代码行数:45,代码来源:config_transform_standalone.py

示例7: sticklet

# 需要导入模块: import random [as 别名]
# 或者: from random import html [as 别名]
def sticklet(event):
    R = random.randint(0,256)
    G = random.randint(0,256)
    B = random.randint(0,256)

    # get the input text
    # the text on which we would like to do the magic on
    sticktext = event.pattern_match.group(1)

    # delete the userbot command,
    # i don't know why this is required
    await event.delete()

    # https://docs.python.org/3/library/textwrap.html#textwrap.wrap
    sticktext = textwrap.wrap(sticktext, width=10)
    # converts back the list to a string
    sticktext = '\n'.join(sticktext)

    image = Image.new("RGBA", (512, 512), (255, 255, 255, 0))
    draw = ImageDraw.Draw(image)
    fontsize = 230

    FONT_FILE = await get_font_file(event.client, "@FontRes")

    font = ImageFont.truetype(FONT_FILE, size=fontsize)

    while draw.multiline_textsize(sticktext, font=font) > (512, 512):
        fontsize -= 3
        font = ImageFont.truetype(FONT_FILE, size=fontsize)

    width, height = draw.multiline_textsize(sticktext, font=font)
    draw.multiline_text(((512-width)/2,(512-height)/2), sticktext, font=font, fill=(R, G, B))

    image_stream = io.BytesIO()
    image_stream.name = "@UniBorg.webp"
    image.save(image_stream, "WebP")
    image_stream.seek(0)

    # finally, reply the sticker
    #await event.reply( file=image_stream, reply_to=event.message.reply_to_msg_id)
    #replacing upper line with this to get reply tags

    await event.client.send_file(event.chat_id, image_stream, reply_to=event.message.reply_to_msg_id)
    # cleanup
    try:
        os.remove(FONT_FILE)
    except:
        pass 
开发者ID:mkaraniya,项目名称:BotHub,代码行数:50,代码来源:sticklet_un.py

示例8: parse_range_header

# 需要导入模块: import random [as 别名]
# 或者: from random import html [as 别名]
def parse_range_header(range_header_val, valid_units=('bytes',)):
    """
    Range header parser according to RFC7233

    https://tools.ietf.org/html/rfc7233
    """

    split_range_header_val = range_header_val.split('=')
    if not len(split_range_header_val) == 2:
        raise RangeHeaderParseError('Invalid range header syntax')

    unit, ranges_str = split_range_header_val

    if unit not in valid_units:
        raise RangeHeaderParseError('Invalid unit specified')

    split_ranges_str = ranges_str.split(', ')

    ranges = []

    for range_str in split_ranges_str:
        re_match = BYTE_RANGE_RE.match(range_str)
        first, last = None, None

        if re_match:
            first, last = re_match.groups()
        else:
            re_match = SUFFIX_BYTE_RANGE_RE.match(range_str)
            if re_match:
                first = re_match.group('first')
            else:
                raise RangeHeaderParseError('Invalid range format')

        if first is not None:
            first = int(first)


        if last is not None:
            last = int(last)

        if last is not None and first > last:
            raise RangeHeaderParseError('Invalid range, first %s can\'t be greater than the last %s' % (unit, unit))

        ranges.append((first, last))

    return ranges 
开发者ID:scitran,项目名称:core,代码行数:48,代码来源:util.py


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