krand

package
v1.5.5 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2023 License: MIT Imports: 2 Imported by: 0

README

krand

Generate random strings, integers, floating point numbers.


Example of use

Generate a random string

    import "github.com/liuzw3018/sponge/pkg/krand"

    /*
	R_NUM = 1      // only number
	R_UPPER = 2   // only capital letters
	R_LOWER = 4  // only lowercase letters
	R_All = 7	       // numbers, upper and lower case letters
    */

	// by | or combining different types
    kind := krand.R_NUM|krand.R_UPPER    // capital letters and numbers

	// a random string of length 10, consisting of upper case letters and numbers
    krand.String(kind, 10)

Generate random integers

    import "github.com/liuzw3018/sponge/pkg/krand"

    krand.Int(200)            // random number range 0 ~ 200
    krand.Int(1000, 2000)  // random number range 1000 ~ 2000

Generate random floating point numbers

    import "github.com/liuzw3018/sponge/pkg/krand"

    krand.Float64(1, 200)            // floating point number with 1 decimal point, range 0~200
    krand.Float64(2, 100,1000)            // floating point number with 2 decimal places, range 100~1000

Documentation

Overview

Package krand is a library for generating random strings, integers, floating point numbers.

Index

Constants

View Source
const (
	R_NUM   = 1 // only number
	R_UPPER = 2 // only capital letters
	R_LOWER = 4 // only lowercase letters
	R_All   = 7 // numbers, upper and lower case letters
)

nolint

Variables

This section is empty.

Functions

func Bytes

func Bytes(kind int, bytesLen ...int) []byte

Bytes generate random strings of any length of multiple types, default length is 6 if bytesLen is empty example: Bytes(R_ALL), Bytes(R_ALL, 16), Bytes(R_NUM|R_LOWER, 16)

func Float64

func Float64(dpLength int, rangeSize ...int) float64

Float64 generates a random floating point number of the specified range size, Four types of passing references are supported, example: Float64(dpLength), Float64(dpLength, max), Float64(dpLength, min, max), Float64(dpLength, max, min), min<=random numbers<=max

func Int

func Int(rangeSize ...int) int

Int generate random numbers of specified range size, compatible with Int(), Int(max), Int(min, max), Int(max, min) 4 ways, min<=random number<=max

func String

func String(kind int, size ...int) string

String generate random strings of any length of multiple types, default length is 6 if size is empty example: String(R_ALL), String(R_ALL, 16), String(R_NUM|R_LOWER, 16)

Types

This section is empty.

Jump to

Keyboard shortcuts

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