From 2f9b75f5d72c39667df34a8bf65ca0b6dcfd460b Mon Sep 17 00:00:00 2001 From: Phxntxm Date: Sat, 13 Aug 2016 14:58:47 -0500 Subject: [PATCH] Changed random generating to use SystemRandom, for better random numbers --- cogs/core.py | 6 +++--- cogs/interaction.py | 6 +++--- cogs/links.py | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cogs/core.py b/cogs/core.py index f513537..ca34a93 100644 --- a/cogs/core.py +++ b/cogs/core.py @@ -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}!' diff --git a/cogs/interaction.py b/cogs/interaction.py index c58561d..f27e129 100644 --- a/cogs/interaction.py +++ b/cogs/interaction.py @@ -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: diff --git a/cogs/links.py b/cogs/links.py index c69c0b2..705f2e5 100644 --- a/cogs/links.py +++ b/cogs/links.py @@ -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):