Cesura / pastey

A minimal, self-hosted paste platform
https://pastey.link/
BSD 3-Clause "New" or "Revised" License
106 stars 12 forks source link

This is a patch to shorten the URLs generated by pastey #28

Closed stvhay closed 2 years ago

stvhay commented 2 years ago

https://github.com/Cesura/pastey/issues/13

This patch is based on a request to shorten URLs to make them easier to type.

The first URLs is 3 digits long. The second URL is 4 digits long until 17 pastes are made and then go up to 6 digits. As digits continue to increase, probability of collision remains less than 1.9e-6 forever.

stvhay commented 2 years ago
total_items=     1  items=     1    len_url=3   N=           262144 prob=0.0000E+00
total_items=    16  items=    16    len_url=4   N=         16777216 prob=1.1176E-07
total_items=   271  items=   256    len_url=6   N=      68719476736 prob=4.7497E-07
total_items=  4366  items=  4096    len_url=7   N=    4398046511104 prob=1.9069E-06
total_items= 69901  items= 65536    len_url=8   N=  281474976710656 prob=1.1921E-07
stvhay commented 2 years ago

I thought about this some more, and we probably want to keep cumulative probability of a collision low. Anyways, I tweaked the formula to do this.

total_items=     2  items=     2    len_url=3   N=           262144 prob=3.8147E-06 cum_prob=7.6294E-06
total_items=    17  items=    16    len_url=4   N=         16777216 prob=1.1176E-07 cum_prob=1.8999E-06
total_items=   117  items=   101    len_url=6   N=      68719476736 prob=7.3487E-08 cum_prob=8.5980E-06
total_items=   761  items=   645    len_url=7   N=    4398046511104 prob=4.7223E-08 cum_prob=3.5937E-05
total_items=  4856  items=  4096    len_url=8   N=  281474976710656 prob=4.6555E-10 cum_prob=2.2607E-06
total_items= 30862  items= 26007    len_url=10  N=1152921504606846976   prob=2.9331E-10 cum_prob=9.0523E-06
Cesura commented 2 years ago

I think scaling with number of posts is a good idea, thank you :+1: