本文整理匯總了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
示例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
示例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
#------------------------------------------------------------------------
示例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