Git Product home page Git Product logo

shortcodes's Introduction

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)

shortcodes's People

Contributors

zakpatterson avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

zakpatterson

shortcodes's Issues

Pack bits more efficiently in byte array

The default dictionary is 2048 words. So we could pack this in fewer bytes than 2 per word, since it is 11 bits per word.

So a sequence of 4 words could be stored in 6 bytes instead of 8.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.