I need to generate a random string (8 digit alphanumeric code) and save it with my Tournament row into a database.
Problem is that this code needs to be unique in the whole table and random (not incremental) because I don't want it to be predictable (people using it to join tournament).
So I need something to genreate a code but when it already is in table then generate new one. One way is to generate code, then check database existance, then generate new in case of conflict. But this solution have many problems like it can run forever and its is slow.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…