Giter VIP home page Giter VIP logo

permutor's Introduction

permutor

permutor is a library to create randomly unique (there is no way for that but however) characters from given letters for range of start and end length

how it's works?

when you need a 3 random letter from set of a-zA-Z0-9 that means you need one element from set of 3 chars, this set is a calculable and reproducible. every generate call i select a random number between 0 and length of set (max possibility for 3 char set of AZaz09 is 238328) then i check from bitset for prevent generate same element again and again

if you give a range (lets say 3 and 6 char) after i generate all possibilities of 3 letter then i calculate length of set for 4, reset the bitset and continue to generate.

if you are gone stop your application and start again you can save state of current status into a json file and load from it.

be a calculator

when you need a 5 char random letters for A-Za-Z0-9 (916.132.832 possibility), you need a 62**5 / 8 byte memory to (109MB) keep all possibilities in a bitset, when you need a 6 letter than you need a 6GB memory.

Usage of permutor

package main

import (
   "fmt"
   "github.com/selam/permutor"
)

func main() {
   // first parameter is a alphabet, second parameter is a min length of letters
   // third parameter is max length of letters
   rp, err := permutor.NewPermutor("abcdefgh", 3, 6)
   if err != nil {
        fmt.Printf("there is a error in parameters %s\n", err.Error());
        return
   }
   letters, posibility := rp.Generate()
   if letters == "" {
      fmt.Println("all posilible elements are already created, you can reset or finish")
   }

   fmt.Printf("%d pobisibility is %s\n", possibility, letters)

   err = rp.SaveTo("/path/to/file.json")  // so you can read from another lib writed another language
   if err != nil {
      fmt.Printf("there is a error when saving state: %s\n", err.Error())
      return // or do it something else
   }

   second, err := permutor.LoadFrom("/path/to/file.json")
   if err != nil {
          fmt.Printf("there is a error when loading state: %s\n", err.Error())
          return // or do it something else
   }

   letters, _ = second.Generate() // letters already defined
   if letters == "" {
         fmt.Println("all posilible elements are already created, you can reset or finish")
         return
   }
}

permutor's People

Contributors

selam avatar tuyan avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

tuyan

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.