rango

package module
Version: v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

README

Go version Go coverage GitHub license

RanGo Logo

🦎RanGo

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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RandomInt

func RandomInt(startIncluded int, endNotIncluded int) (randomInt int, isSeedTimeDependent bool)

RandomInt generates a random int

func RandomString

func RandomString(length int, containsLowercase bool, containsUppercase bool, containsNumber bool, containsSpecial bool) (randomString string, isSeedTimeDependent bool)

RandomString generates a random string

func RandomStringFrom

func RandomStringFrom(length int, chars string) (randomString string, isSeedTimeDependent bool)

RandomStringFrom generates a random string with the given characters

func RnInt

func RnInt(startIncluded int, endNotIncluded int) (randomInt int)

RnInt generates a random int

func RnString

func RnString(length int, containsLowercase bool, containsUppercase bool, containsNumber bool, containsSpecial bool) (randomString string)

RnString generates a random string

func RnStringFrom

func RnStringFrom(length int, chars string) (randomString string)

RnStringFrom generates a random string with the given characters

Types

This section is empty.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL