skorokithakis / shortuuid

A generator library for concise, unambiguous and URL-safe UUIDs.
http://www.stavros.io/
BSD 3-Clause "New" or "Revised" License
2.07k stars 112 forks source link

Changing alphabet change shortuuid length to 25 #98

Closed KinanLak closed 1 year ago

KinanLak commented 1 year ago

Hello,

When I'm trying to generate an uuid this happens :

Step to reproduce (Python 3.11.2 Shortuuid 1.0.11) :

>>> import shortuuid
>>> shortuuid.get_alphabet()
'23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
>>> shortuuid.uuid()
'iaFttNEzNGCcwUfYsKhvjr'
>>> shortuuid.set_alphabet('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ')
>>> shortuuid.uuid()
'2STM4XVS7Y6MMJX1VJIOWN1ZK'

'iaFttNEzNGCcwUfYsKhvjr' has a len of 22 But '2STM4XVS7Y6MMJX1VJIOWN1ZK' has a len of 25

I don't really know why this occurs

skorokithakis commented 1 year ago

Shorter alphabets produce longer strings, since you need to fit a fixed number of bits in them.