Browse Source

Improve local images randomness by using random.SystemRandom()

My bot @gracyimp@botsin.space gave me the same image twice this morning,
within a few seconds, so I asked myself how to improve the randomness.
Indeed, this allowed my bot to publish some images that never were
published!
pull/17/head
Luc Didry 11 months ago
parent
commit
e5e4938479
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS. GPG Key ID: EA868E12D0257E3C
1 changed files with 2 additions and 1 deletions
  1. +2
    -1
      bot.py

+ 2
- 1
bot.py View File

@@ -32,7 +32,8 @@ def post_img_local(mastodon, text, log, config):

continu = True;
while continu:
file = random.choice(os.listdir(img_path+"/"))
secure_random = random.SystemRandom()
file = secure_random.choice(os.listdir(img_path+"/"))
if os.path.isdir(img_path+file):
img_path = img_path+file+"/"
else:


Loading…
Cancel
Save