本文整理汇总了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