Skip to content

YektaDev/RanGo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RanGo Logo

🦎RanGo PkgGoDev Go Report Card Go version Go coverage GitHub license

A time-independent random number/string generator.

📦Installation

First:

go get github.com/yektadev/rango

Then, add the dependency to your code:

import "github.com/yektadev/rango"

📝Simple Usage

Here's all you need to do in order to:

🔺Generate a random int:

Use:

RanGo.RnInt(startIncluded int, endNotIncluded int)

Example:

r := RanGo.RnInt(0,8)  //r ϵ {0,1,2,...,6,7}

🔺Generate a random string from a set of characters:

Use:

RanGo.RnStringFrom(length int, chars string)

Example:

r := RanGo.RnStringFrom(8,"abcd")  //r (example): "dadaadbb"

🔺Generate a random string:

Use:

RanGo.RnString(length int, containsLowercase bool, containsUppercase bool, containsNumber bool, containsSpecial bool)

Examples:

r := RanGo.RnString(18,true,true,true,true)  //r (example): "}WCg*(?w4P$<HS\jOb"
r := RanGo.RnString(18,true,false,false,false)  //r (example): "jzoqagpchhsyhotvrj"
r := RanGo.RnString(18,false,false,true,false)  //r (example): "325803510203358683"

🔧More Options

If the above functions face an error while generating a time-independent seed, the seed will be automatically generated using time.Now().UnixNano(). If you need to know whether the seed is generated time-dependent or time-independent, then use the following functions:

  • RandomInt() instead of RnInt().
  • RandomStringFrom() instead of RnStringFrom().
  • RandomString() instead of RnString().

In case of using these functions, you'll have isSeedTimeDependent boolean as the second returned output.


Special thanks to John Leidegren because of this answer on Stack Overflow.

About

A safe time-independent random number/string generator.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages