Skip to content

Praseetha-KR/strand

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

strand

GoDoc GitHub Actions status

A tiny go package for generating random strings

strand generates string randoms containing alphabets, digits and special characters. The randomness is seeded internally with the timestamp of package initialization.

Install

go get -u github.com/Praseetha-KR/strand

Sample Usage:

package main

import (
  "fmt"
  "github.com/Praseetha-KR/strand"
)

func main() {
  fmt.Println(strand.String(24))
}

Available Methods

Method Character Set Example
String(length)
All supported characters
Usage: r := strand.String(20)
Output: vT7+Bt/])o+66H<[GG[s
Alpha(length)
Alphabet
Usage: r := strand.Alpha(20)
Output: PNsxdCsGyLDEFzQxcZSy
AlphaLower(length)
Alphabet Lowercase
Usage: r := strand.AlphaLower(20)
Output: ivkosjouadiecjvdanct
AlphaUpper(length)
Alphabet Uppercase
Usage: r := strand.AlphaUpper(20)
Output: QUXMYZJUHIOZPOAAASFI
AlphaNumeric(length)
Alphabet and Digits
Usage: r := strand.AlphaNumeric(20)
Output: 1CxlOZp3yVwoGeqIjimH
Numeric(length)
Digits
Usage: r := strand.Numeric(20)
Output: 93422189029287851575
URLSafe(length)
url-safe characters
Usage: r := strand.URLSafe(20)
Output: P~8i1aEP_PGWXyHUVmO8
Hex(length)
Hexadecimal characters
Usage: r := strand.Hex(20)
Output: b0590721d92ce097b8a3
Binary(length)
Binary digits
Usage: r := strand.Binary(20)
Output: 10100011000101110011
From(characters, length)
Provided by `characters` param
Usage: r, err := strand.From("abc#123", 20)
Output: #1a#cc33ccb2131a1233

Author: Praseetha-KR (@void_imagineer)

License: MIT