Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.kag0:ruid:1.1.0'
}
dependencies {
implementation("com.github.kag0:ruid:1.1.0")
}
<dependency>
<groupId>com.github.kag0</groupId>
<artifactId>ruid</artifactId>
<version>1.1.0</version>
</dependency>
libraryDependencies += "com.github.kag0" % "ruid" % "1.1.0"
:dependencies [[com.github.kag0/ruid "1.1.0"]]
RUIDs are uniformly distributed, are 24 URI-safe ASCII characters when encoded,
and are unique by 18 random bytes. They look like this: 9uZIuRrbPRl71PiRAmUID9xd
.
Anywhere you need a non-sequential unique id.
RUID myRuid = RUID.generate();
RUID parsed = RUID.parse("9uZIuRrbPRl71PiRAmUID9xd");
byte[] binary = myRuid.bytes();
String encoded = myRuid.toString();
A RUID is 18 random bytes, Base64Url encoded when needed in text form. It can be stored or transmitted in its binary for speed and efficiency, or encoded for use in text-based protocols.
UUIDs require the ability to determine the version of the UUID, and then verify
the structure of the UUID against that version. RUIDs have no such structure and
simply require decoding using base64url which is fast, well known, and widely
available in most languages.
UUIDs also do not truncate well. Removing characters from the beginning or end of
a UUID can at best disproportionately decrease the uniqueness (with respect to
the number of characters removed), and at worst completely remove uniqueness.
RUIDs have no such issues, removing characters removes proportional uniqueness,
regardless of where in the RUID the character was removed from.
Deprecated in favor of version 5
Version 4 UUIDs are the most common and widely used version. They use about 15
bytes of random data to achieve uniqueness, but require 16 bytes to store.
Due to their hex encoding and part separation, they take 36 ASCII characters to display when encoded.
RUIDs on the other hand are only 2/3 the size of UUIDv4 when encoded, yet describe 22 bits more.
Only useful in identifying named resources, not as database key, nonce, or other such use.