本文整理汇总了Python中random.SystemRandom.randint方法的典型用法代码示例。如果您正苦于以下问题:Python SystemRandom.randint方法的具体用法?Python SystemRandom.randint怎么用?Python SystemRandom.randint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类random.SystemRandom
的用法示例。
在下文中一共展示了SystemRandom.randint方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_stress
# 需要导入模块: from random import SystemRandom [as 别名]
# 或者: from random.SystemRandom import randint [as 别名]
def test_stress(self):
"""
Runs a large number of threads doing operations with resources
checked out, ensuring properties of the pool.
"""
rand = SystemRandom()
n = rand.randint(1, 400)
passes = rand.randint(1, 20)
rounds = rand.randint(1, 200)
breaker = rand.uniform(0, 1)
pool = EmptyListPool()
def _run():
for i in range(rounds):
with pool.transaction() as a:
self.assertEqual([], a)
a.append(currentThread())
self.assertEqual([currentThread()], a)
for p in range(passes):
self.assertEqual([currentThread()], a)
if rand.uniform(0, 1) > breaker:
break
a.remove(currentThread())
threads = []
for i in range(n):
th = Thread(target=_run)
threads.append(th)
th.start()
for th in threads:
th.join()
示例2: genKeys
# 需要导入模块: from random import SystemRandom [as 别名]
# 或者: from random.SystemRandom import randint [as 别名]
def genKeys(nbits):
p,nchecks = findPrime(nbits)
r1 = SystemRandom(time.time())
r2 = SystemRandom(time.time())
a = r1.randint(1,p-2)
k = r2.randint(1,p-2)
pubkey = (p,a,pow(a,k,p))
prikey = k
return (pubkey,prikey)
示例3: test_listPointGenerator
# 需要导入模块: from random import SystemRandom [as 别名]
# 或者: from random.SystemRandom import randint [as 别名]
def test_listPointGenerator(self):
r = SystemRandom()
for i in range(10):
p = getRandPrime(5)
while p <= 10:
p = getRandPrime(5)
e = ecc.ECC(r.randint(1, 100), r.randint(1, 100), p)
for point in e.listPointGenerator():
self.assertTrue(e.isInCurve(point))
示例4: test_basePoint
# 需要导入模块: from random import SystemRandom [as 别名]
# 或者: from random.SystemRandom import randint [as 别名]
def test_basePoint(self):
r = SystemRandom()
for i in range(10):
p = getRandPrime(5)
while p <= 10:
p = getRandPrime(5)
e = ecc.ECC(r.randint(1, 100), r.randint(1, 100), p)
G = e.G
self.assertTrue(e.isInCurve(G))
示例5: test_add
# 需要导入模块: from random import SystemRandom [as 别名]
# 或者: from random.SystemRandom import randint [as 别名]
def test_add(self):
r = SystemRandom()
for i in range(10):
p = getRandPrime(5)
while p <= 10:
p = getRandPrime(5)
e = ecc.ECC(r.randint(1, 100), r.randint(1, 100), p)
all_points = list(e.listPointGenerator())
for j in range(100):
point1 = r.choice(all_points)
point2 = r.choice(all_points)
point = e.add(point1, point2)
self.assertEqual(e.isInCurve(point), True)
示例6: roll
# 需要导入模块: from random import SystemRandom [as 别名]
# 或者: from random.SystemRandom import randint [as 别名]
def roll(count, sides):
results = []
rand = SystemRandom()
for x in range(count):
if sides == 100 or sides == 1000:
#Special Case for 100 sized dice
results.append(rand.randint(1, 10))
results.append(rand.randrange(0, 100, 10))
if sides == 1000:
results.append(rand.randrange(0, 1000, 100))
else:
results.append(rand.randint(1, sides))
return results
示例7: generate_keys
# 需要导入模块: from random import SystemRandom [as 别名]
# 或者: from random.SystemRandom import randint [as 别名]
def generate_keys(parties_number):
""" generates a private key and saves it to a file. publishes public key to BB.
"""
private_keys = []
for party_id in range(1, parties_number + 1):
rng = SystemRandom()
private_key = rng.randint(2, VOTING_CURVE.order)
while private_key in private_keys:
private_key = rng.randint(2, VOTING_CURVE.order)
public_key = VOTING_CURVE.get_member(private_key)
data = dict(party_id=party_id, first=str(public_key.x), second=str(public_key.y))
publish_dict(data, LOCAL_BB_URL + PUBLISH_PUBLIC_KEY_TABLE_FOR_PARTIES)
filename = PRIVATE_KEYS_PATH + "privateKey_" + str(party_id) + ".txt"
f = open(filename, "w")
f.writelines(["party id: \n", str(party_id) + "\n", "private key:\n", str(private_key) + "\n"])
f.close()
示例8: sign
# 需要导入模块: from random import SystemRandom [as 别名]
# 或者: from random.SystemRandom import randint [as 别名]
def sign(self, message):
""" Signs message using ECDSA.
:param message: bytes to sign
:return: bytes representing r, s.
"""
m = hashlib.sha256()
m.update(message)
e = m.digest()
ln = self.sign_curve.order.bit_length() // 8
n = self.sign_curve.order
z = e[0:ln]
z = int.from_bytes(z, byteorder="big") # Matching the BigInteger form in the java signing.
certificate = 0
while certificate == 0:
rng = SystemRandom()
k = rng.randint(1, n)
kg = self.sign_curve.get_member(k)
r = kg.x
if r == 0:
continue
s = (mod_inv(k, n) * (z + (r * self.sign_key) % n) % n) % n
if s == 0:
continue
l = [r, s]
int_length = self.sign_curve.int_length // 8
certificate = list_to_bytes(l, int_length)
return certificate
示例9: random_password
# 需要导入模块: from random import SystemRandom [as 别名]
# 或者: from random.SystemRandom import randint [as 别名]
def random_password(description, min_chars=10, max_chars=20):
"""
Creates a random password from uppercase letters, lowercase letters and
digits with a length between min_chars and max_chars
"""
# Open saved passwords file or create new one.
try:
fh = open("info/passwords.json", "r+")
passwords = json.load(fh)
except IOError:
fh = open("info/passwords.json", "w+")
passwords = {}
# Return password if it exists already
if description in passwords:
fh.close()
return passwords[description]
# Create new password if it does not exist
else:
seeded_random = SystemRandom()
chars = ascii_letters + digits
password_length = seeded_random.randint(min_chars, max_chars)
password = "".join(seeded_random.choice(chars) for _ in range(password_length))
passwords[description] = password
fh.seek(0)
json.dump(passwords, fh, indent=4)
fh.close()
return password
示例10: generate_question
# 需要导入模块: from random import SystemRandom [as 别名]
# 或者: from random.SystemRandom import randint [as 别名]
def generate_question(self):
"""Generate random question."""
generator = SystemRandom()
operation = generator.choice(self.operators)
first = generator.randint(self.interval[0], self.interval[1])
second = generator.randint(self.interval[0], self.interval[1])
# We don't want negative answers
if operation == '-':
first += self.interval[1]
return ' '.join((
str(first),
operation,
str(second)
))
示例11: getFiles
# 需要导入模块: from random import SystemRandom [as 别名]
# 或者: from random.SystemRandom import randint [as 别名]
def getFiles(gendpointDict, uendpoint, username, upath):
label = str(uuid4())
endNames = gendpointDict.keys()
for thisEndName in endNames:
fileList = gendpointDict[thisEndName]
cryptogen = SystemRandom()
transferFile = '/tmp/transferList_' + thisEndName + '_' + str(cryptogen.randint(1,9999)) + '.txt'
file = open(transferFile, 'w')
for thisFile in fileList:
basename = os.path.basename(thisFile)
if upath[-1] != '/':
basename = '/' + basename
remote = thisFile
local = upath + basename
file.write(remote + ' ' + local + '\n')
file.close()
os.system("globus transfer "+thisEndName+" "+uendpoint+" --batch --label \"CLI Batch\" < "+transferFile)
os.remove(transferFile)
return
示例12: populate
# 需要导入模块: from random import SystemRandom [as 别名]
# 或者: from random.SystemRandom import randint [as 别名]
def populate(self, *excludePSets):
"""
_populate_
generate a bunch of seeds and stick them into this service
This is the lazy user method.
Optional args are names of PSets to *NOT* alter seeds.
Eg:
populate() will set all seeds
populate("pset1", "pset2") will set all seeds but not those in
psets named pset1 and pset2
"""
import random
from random import SystemRandom
_inst = SystemRandom()
_MAXINT = 900000000
# //
# // count seeds and create the required number of seeds
#//
newSeeds = [ _inst.randint(1, _MAXINT)
for i in range(self.countSeeds())]
self._lockedSeeds = list(excludePSets)
self.insertSeeds(*newSeeds)
self._lockedSeeds = []
return
示例13: main
# 需要导入模块: from random import SystemRandom [as 别名]
# 或者: from random.SystemRandom import randint [as 别名]
def main(args):
r = SystemRandom()
try:
try:
_min = int(args[1])
_max = int(args[2])
except:
_min = 0
_max = int(args[1])
except:
_min = 0
_max = 10
try:
if args[0] == 'simple':
l = list(string.letters + string.digits)
r.shuffle(l)
return ''.join(l[0:_max])
if args[0] == 'strong':
l = list(string.letters + string.digits + string.punctuation)
r.shuffle(l)
return ''.join(l[0:_max])
if args[0] == 'integer':
return r.randint(_min, _max)
return r.uniform(_min, _max)
except:
return r.random()
示例14: csprng
# 需要导入模块: from random import SystemRandom [as 别名]
# 或者: from random.SystemRandom import randint [as 别名]
def csprng(low, high, offset=0):
rng = SystemRandom()
rnum = rng.randint(low, high-1) + offset
if rnum < 0:
print("[-] Error: Random number generator returned out of bounds.")
return None
return rnum
示例15: statsGen
# 需要导入模块: from random import SystemRandom [as 别名]
# 或者: from random.SystemRandom import randint [as 别名]
def statsGen():
rand = SystemRandom()
while True:
stats = []
for s in range(0, 6): # Six Stats
rolls = []
for d in range(0, 4): # Four Dice
roll = rand.randint(1, 6)
if roll == 1: # Reroll 1's once
roll = rand.randint(1, 6)
rolls.append(roll)
rolls.sort()
rolls.reverse()
stats.append(rolls[0] + rolls[1] + rolls[2])
if statsCheck(stats):
return stats
return None