I discovered that this problem is, in essence, the birthday problem. To anyone curious, the answer is 8446. This problem was for a computer science class. All things considered, if you want an 8-digit primary key for a database and intend to fill up the table with well more than 8446 rows, you had better take into account that there's a 30% probability that two are equal if you generate the keys randomly. And with each additional row, the probability that two are equal grows steeply and then quickly approaches one.