Commit 6028519c authored by Otthorn's avatar Otthorn 🤔

Added better random

parent e9057f4a
from random import shuffle
dico = {}
def cycle(L):
"""cycle one iteration of a list"""
return L[1:] + [L[0]]
def get_random_id(query, maximum_id):
if query not in dico:
list_id = list(range(maximum_id))
dico[query] = list_id
dico[query] = cycle(dico[query])
return dico[query][0]
import random
import better_random
import json
from urllib.request import urlopen
from urllib.parse import quote_plus
......@@ -20,8 +20,9 @@ def gif_search(query, query_type, api_key, limit):
if maximum_id == -1:
return query
random_id = random.randint(0, maximum_id)
#random_id = random.randint(0, maximum_id)
random_id = better_random.get_random_id(query, maximum_id)
print("Search id: {}/{}".format(random_id, maximum_id))
id_url = data['data'][random_id]['id']
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment