As mentioned in the comments of mt_rand() it is weak in security and we should use /dev/urandom instead. My problem is that from urandom I get a binary string.
How do I convert this binary string to 0-9a-zA-Z?
Looks like base_convert() does not work here.
Just for the record the full function: