1A programmatic way can be to:
2
3add a UNIQUE INDEX to the field
4generate a random string in PHP
5loop in PHP ( while( ! DO_THE_INSERT ) )
6generate another string
7Note:
8
9This can be dirty, but has the advantage to be DBMS-agnostic
10Even if you choose to use a DBMS specific unique ID generator function (UUID, etc) it is a best practice to assure the field HAS to be UNIQUE, using the index
11the loop is statistically not executed at all, it is entered only on insert failure