vinkla / hashids

A small PHP library to generate YouTube-like ids from numbers. Use it when you don't want to expose your database ids to the user.
https://hashids.org/php
MIT License
5.28k stars 418 forks source link

How can I get more randomness? #184

Closed cacharrin closed 2 years ago

cacharrin commented 2 years ago

This is just a question.

I just tried to generate 1300 codes using;

$alphabet = "bcdfghjkmnpqrstvwxz23456789";
$h = new Hashids("pHQuT51S4R", 5, $alphabet);

echo $h->encode(1);
echo $h->encode(2);
echo $h->encode(3);
echo $h->encode(4);
...
echo $h->encode(1299);
echo $h->encode(1300);

Is it normal that 98.6% of the codes starts with "8" or "r"? Is it normal that all the first 322 codes also ends with "8" or "r"? Is there a way to get more randomness in the codes?

I tried to change the alphabet, but the pattern just change for a different letters, but the vast majority of the codes have the same starting or ending character set.

vinkla commented 2 years ago

https://github.com/vinkla/hashids/pull/183#issuecomment-1183279181=