Single Example

  
Possible Characters:
Number of Characters:
Number of Items:
 
Number of possible values:
Chance of no collisions:
Chance of collision 1 in x:
 

Table of Examples

    Scenario 1 Scenario 2 Scenario 3 Scenario 4
Possible Chars Num Chars
Set all num chars:

This tool calculates how likely it is that when generating random strings of characters you will get two with the same value (a collision). When generating a large number of these random values the chances of a collision goes up quickly, often much faster than expected. For example, if you're generating random 4 digit numbers, there are 10,000 possibilities, and so the chance of any one of those random numbers being the same as another is 1 in 10,000. However, every time you generate a new number you must compare it to all prior numbers, and so the number of comparisons can get very large, which can lead to the chance of a collision being higher than expected. The Birthday Paradox describes the surprising fact that it only takes 23 people before the chance that two of them will share the same birthday to be over 50%. That is not a paradox, but the number is much lower than people generally expect.

I made this tool mainly to show how much better using the full space of lowercase letters and numbers (36 characters) is than just using hex (16 characters) when generating random IDs. Developers often default to generating random IDs in hex because it's easy, but using the full space of the alphabet greatly reduces the chance that two randomly generated IDs will be the same, and including upper and lowercase letters reduces it much more. As an example, if you're going to have 6 character IDs, the chance of a collision if you generate 1000 is 2.9% with hex, 0.023% with alphanumeric, and 0.00088% with upper and lower alphanumeric. You could generate over 50,000 of the case sensative IDs and still have a lower chance of a collision (2.18%) than if you used just hex and only generated 1000 (2.93%).

Note this tool is using native javascript numbers, which have a precision limit of about 15 decimal places. When showing the chance of no collisions and using values that give a very small chance of a collision you'll see 1, when really the answer is a very small number less than 1. Just know that the chance of a collision is never 0, and so the chance of no collision is never truly 1. Viewing the chance of a collision (rather than the chance of no collision) should never round to 0.