1
0
Fork 0
mirror of synced 2024-06-26 10:10:44 +12:00

Changed random generating to use SystemRandom, for better random numbers

This commit is contained in:
Phxntxm 2016-08-13 14:58:47 -05:00
parent aaa63a7c27
commit 2f9b75f5d7
3 changed files with 8 additions and 8 deletions

View file

@ -77,7 +77,7 @@ class Core:
async def doggo(self, ctx):
"""Use this to print a random doggo image.
Doggo is love, doggo is life."""
f = glob.glob('images/doggo*')[random.randint(0, len(glob.glob('images/doggo*')) - 1)]
f = glob.glob('images/doggo*')[random.SystemRandom().randint(0, len(glob.glob('images/doggo*')) - 1)]
with open(f, 'rb') as f:
await self.bot.upload(f)
@ -86,7 +86,7 @@ class Core:
async def snek(self, ctx):
"""Use this to print a random snek image.
Sneks are o3o"""
f = glob.glob('images/snek*')[random.randint(0, len(glob.glob('images/snek*')) - 1)]
f = glob.glob('images/snek*')[random.SystemRandom().randint(0, len(glob.glob('images/snek*')) - 1)]
with open(f, 'rb') as f:
await self.bot.upload(f)
@ -120,7 +120,7 @@ class Core:
await self.bot.say("What die has more than 100 sides? Please, calm down")
return
valueStr = ", ".join(str(random.randint(1, num)) for i in range(0, int(dice)))
valueStr = ", ".join(str(random.SystemRandom().randint(1, num)) for i in range(0, int(dice)))
if dice == 1:
fmt = '{0.message.author.name} has rolled a {2} sided die and got the number {3}!'

View file

@ -121,10 +121,10 @@ class Interaction:
battleP1 = discord.utils.find(lambda m: m.id == p1[0], ctx.message.server.members)
battleP2 = ctx.message.author
fmt = config.battleWins[random.randint(0, len(config.battleWins) - 1)]
fmt = config.battleWins[random.SystemRandom().randint(0, len(config.battleWins) - 1)]
battlingOff(ctx.message.author.id)
if random.randint(1, 100) < 50:
if random.SystemRandom().randint(0, 1):
await self.bot.say(fmt.format(battleP1.mention, battleP2.mention))
updateBattleRecords(battleP1, battleP2)
else:

View file

@ -55,7 +55,7 @@ class Links:
# Get the link if it exists, if not return saying no results found
if len(results) > 0:
index = random.randint(0, len(results) - 1)
index = random.SystemRandom().randint(0, len(results) - 1)
imageLink = 'http://{}'.format(results[index].get('representations').get('full')[2:].strip())
else:
await self.bot.say("No results with that search term, {0}!".format(ctx.message.author.mention))
@ -97,7 +97,7 @@ class Links:
if len(data) == 1:
rand_image = data[0]['file_url']
else:
rand_image = data[random.randint(0, len(data)-1)]['file_url']
rand_image = data[random.SystemRandom().randint(0, len(data)-1)]['file_url']
await self.bot.say(rand_image)
def setup(bot):