Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.
/ shortcodes Public archive

A basic random unique word string generator and codec

Notifications You must be signed in to change notification settings

clovellytech/shortcodes

Repository files navigation

Short codes for Scala Build Status Sonatype Release

This project uses a dictionary of words to generate random short sequences. These are intended for generating site invitation codes, but could probably be used for other purposes.

For now this is only using the bip-39 word list. The dictionary has 2048 words, and the sequence generator chooses with replacement, so the randomness for length n is 2048n. So there are 1.8 x 1013 combinations of 4 words for example. A string of n words will have about the same randomness as an alphanumeric string of length 2n.

Use

Published to sonatype for scala 2.12 and 2.13:

libraryDependencies += "com.clovellytech" %% "shortcodes" % version // look at nexus badge for recent version ^^

Example

scala> val sc = new ShortCode[IO](blocker)
sc: com.clovellytech.shortcode.ShortCode[cats.effect.IO] = com.clovellytech.shortcode.ShortCode@2f738d7f

scala> sc.getRandom(4).value.unsafeRunSync.get
res0: (cats.data.NonEmptyVector[String], Array[Byte]) = (NonEmptyVector(join, jewel, practice, mixture, inhale),Array(3, -63, 3, -65, 5, 75, 4, 114, 3, -99))

scala> sc.bytesToWords(res0._2).value.unsafeRunSync().get
res1: cats.data.NonEmptyVector[String] = NonEmptyVector(join, jewel, practice, mixture, inhale)

About

A basic random unique word string generator and codec

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages