Advertisement
gabrielesilinic

MySQL randomly created UID collisions test tool

Jun 20th, 2021
765
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.25 KB | None | 0 0
  1. from random import randint as rnd
  2. import sys
  3. import mysql.connector#pip install mysql-connector-python
  4. conn= mysql.connector.connect(host="localhost",user="root",database="uids",passwd="root")
  5. cur=conn.cursor()
  6. uidmax=2147483647
  7. maxels=2000000000
  8. #note: the database it's just one column for numbers, the dable it's called ids and the database it's called uids
  9. def get(query):
  10.     cur.execute(query)
  11.     return cur.fetchall();
  12. doesExist= lambda item, equalto : not get("SELECT * FROM ids where {}={}".format(item,equalto))==[]
  13.  
  14. print("uidmax: "+str(uidmax))
  15. uids=set([])
  16. colls=0
  17. for i in range(maxels):
  18.     cy=True
  19.     uid=0
  20.     if i%int(maxels*0.00001)==0:
  21.         print("{}/{}, {}, {} collisions so far".format(i,maxels,i/maxels,colls))
  22.     while cy:
  23.         uid=rnd(0,uidmax)
  24.         if doesExist("id",uid):
  25.             colls+=1
  26.             print("collision {}, index {}".format(colls,i))
  27.         else:
  28.             cy=False
  29.             cur.execute("INSERT INTO ids VALUES({})".format(uid))
  30. #    print("index {} passed as {}".format(i,uid))
  31. print(colls)
  32. conn.close()
  33. print("{} collisions on {} elements, {} rate".format(colls, len(uids), colls/len(uids)))
  34. input("press return to continue...")#safety measure
  35. input("press return to exit...")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement