How to test if a non-repeated random name generator was implemented correctly?

Viewed 150

My goal is to implement a test for a programming exercise. The exercise requires a method for generating random combinations of two uppercase letters and three digits (in that order, eg: QF354). The combinations must be random and non repeating.

How can I test if the method was implemented right?

I was thinking about generating a group of samples and to check for any repeated value, but the number of permutations is too large (p = 26*26*10*10*10 = 676000) for quick tests.

I don't know how big my group of samples should be to affirm (at least with high confidence) that the values are non-repeating. Alternatives are also welcome.

1 Answers

@OleV.V. The material you suggested was enough for me to find a solution.

This was the approximation I used:

p(n,d) = 1 - e^(-(n²/2d);

Where n is the population size and d the sample size.

For my problem, the probability of collisions asymptotically reaches 1 at about 5000 samples. I did some tests with a few different solutions and so far all the results are as expected.

Thanks for the comments!

Related