clovellytech / shortcodes

A basic random unique word string generator and codec

Version Matrix

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.


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: ([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:[String] = NonEmptyVector(join, jewel, practice, mixture, inhale)