quarks
quarks

Reputation: 35276

How to generate unique 4-character random keys from Java

How to generate random 4-character key from these characters: [a-zA-Z0-9]
That is less likely to collide, like a unique ID?

Also having those 62 characters by calculation would result for about 14.7 million keys.

Is there a way to stretch that limit?

Upvotes: 0

Views: 1167

Answers (1)

Peter Lawrey
Peter Lawrey

Reputation: 533500

The maximum possible keys is 62^4. To make this larger you need more possible characters or a longer length.

The simplest way to generate unique ids is to use a counter starting with 0..9, A-Z, a-z etc.

Upvotes: 1

Related Questions