And I need to generate a 4-character string from this set, which is less likely to collide.
Less likely than? There are 62 ^ 4 = 14.8 million of such lines. Due to the paradox of the day, you get a 50% chance of a collision if you randomly generate 3800 of them. If this is unacceptable, no library will help you, you need to use a longer line or set uniqueness explicitly (for example, by incrementing an integer and formatting it in the base 62).
source share