當前位置: 首頁>>代碼示例>>Python>>正文


Python random.randrange方法代碼示例

本文整理匯總了Python中Crypto.Random.random.randrange方法的典型用法代碼示例。如果您正苦於以下問題:Python random.randrange方法的具體用法?Python random.randrange怎麽用?Python random.randrange使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Crypto.Random.random的用法示例。


在下文中一共展示了random.randrange方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __getitem__

# 需要導入模塊: from Crypto.Random import random [as 別名]
# 或者: from Crypto.Random.random import randrange [as 別名]
def __getitem__(self, item):
        if self.first_run:
            Random.atfork()
            self.first_run = False

        content = [random.randrange(0, len(self.chars)) for _ in range(self.n_chars)]

        s = ''.join([self.chars[i] for i in content])

        d = self.gen.generate(s)
        d = Image.open(d)

        label = torch.full((self.n_chars + 2, ), self.tokenizer.EOS_token, dtype=torch.long)

        ts = self.tokenizer.tokenize(s)
        label[:ts.shape[0]] = torch.tensor(ts)

        return img_trans(d), label 
開發者ID:wptoux,項目名稱:attention-ocr,代碼行數:20,代碼來源:dataset.py

示例2: random_string

# 需要導入模塊: from Crypto.Random import random [as 別名]
# 或者: from Crypto.Random.random import randrange [as 別名]
def random_string(length=-1, charset=string.ascii_letters):
    """
    Returns a random string of "length" characters.
    If no length is specified, resulting string is in between 6 and 15 characters.
    A character set can be specified, defaulting to just alpha letters.
    """

    if length == -1:
        length = random.randrange(6, 16)
    rand_string = ''.join(random.choice(charset) for _ in range(length))
    return rand_string 
開發者ID:SySS-Research,項目名稱:outis,代碼行數:13,代碼來源:strings.py

示例3: randomString

# 需要導入模塊: from Crypto.Random import random [as 別名]
# 或者: from Crypto.Random.random import randrange [as 別名]
def randomString(length = -1, charset = string.ascii_letters):
    """
    Author: HarmJ0y, borrowed from Empire
    Returns a random string of "length" characters.
    If no length is specified, resulting string is in between 6 and 15 characters.
    A character set can be specified, defaulting to just alpha letters.
    """
    if length == -1: length = random.randrange(6,16)
    random_string = ''.join(random.choice(charset) for x in range(length))
    return random_string

#------------------------------------------------------------------------ 
開發者ID:Arno0x,項目名稱:WSC2,代碼行數:14,代碼來源:helpers.py

示例4: random_string

# 需要導入模塊: from Crypto.Random import random [as 別名]
# 或者: from Crypto.Random.random import randrange [as 別名]
def random_string(length=-1, charset=string.ascii_letters):
    """
    Returns a random string of "length" characters.
    If no length is specified, resulting string is in between 6 and 15 characters.
    A character set can be specified, defaulting to just alpha letters.
    """
    if length == -1:
        length = random.randrange(6, 16)
    random_string = ''.join(random.choice(charset) for x in range(length))
    return random_string 
開發者ID:EmpireProject,項目名稱:EmPyre,代碼行數:12,代碼來源:helpers.py


注:本文中的Crypto.Random.random.randrange方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。