Random Identifiers adds the lightweight capabilities to generate memorable identifiers by concatenating distinguishable english words together.
Random alphanumeric strings and UUIDs are commonly used for test identifiers. These are easily produced but are more difficult to discern in logs and remember while correlating issues. There are some test data generators (for random names, cities, …) to improve readability as an alternative.
intimas-rhizosphere-acetylenic
rivels-shiel-villadoms
dedifferentiates-barrier-sooms
reface-giggler-slayer
centre-icebound-skulks
<dependency>
<groupId>io.github.devnsi</groupId>
<artifactId>random-ids</artifactId>
<version>1.0.0</version>
<scope>test</scope>
</dependency>
dependencies {
testImplementation 'io.github.devnsi:random-ids:1.0.0'
}
String id = RandomIds.next(); // ceibas-coeval-musher
List<String> ids = RandomIds.next(5); // [ceibas-coeval-musher, ...]
RandomIdGen random = new RandomIdGen("~", 5, new Random(0));
String id = random.next(); // wave~sorages~host~broo~arbutus
RandomIdGen random = new RandomIdGen("", 3, new Random(0));
random.setPostProcessor(word -> word.substring(0, 1).toUpperCase() + word.substring(1));
random.stream().limit(3).forEach(System.out::println);
// WaveSoragesHost
// BrooArbutusAction
// PoshlyExpectancesRoam
The generated identifiers do not necessarily guarantee negligible probability of collision like UUIDs, therefore usage in production is discouraged. The probability is sufficiently low for most applications in tests.
The number of generated identifier in order to have a 50% probability of at least one collision given a combination of two out of 100k words would require approximately 37 million draws for 3 word-combinations.
n(p;d) ≈ sqrt(2d*ln(1/(1-p)))
Words (k) | Combinations (d=w^k) | draws (n) for 50% probability (p=0.5) of collision |
---|---|---|
1 |
100 000^1=100 000 |
≈372 |
2 |
100 000^2=10 000 000 000 |
117 741 |
3 |
100 000^3=1 000 000 000 000 000 |
37 233 000 |
Word list based on https://github.com/sindresorhus/word-list.
Overall amount of words reduced to improve performance and save storage space.
Reduced to 100k words by culling longest and then by every n-th.
Recommended alternatives include: