https://github.com/ihexxa/randstr
Customizable random string generator in Go/Golang.
https://github.com/ihexxa/randstr
generator go golang random-generation random-str random-string seed
Last synced: 12 months ago
JSON representation
Customizable random string generator in Go/Golang.
- Host: GitHub
- URL: https://github.com/ihexxa/randstr
- Owner: ihexxa
- License: mit
- Created: 2020-11-19T12:54:23.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2022-07-11T13:12:01.000Z (over 3 years ago)
- Last Synced: 2025-02-15T11:45:43.676Z (about 1 year ago)
- Topics: generator, go, golang, random-generation, random-str, random-string, seed
- Language: Go
- Homepage:
- Size: 9.77 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# randstr
[](https://travis-ci.org/ihexxa/q-radix)
[](https://goreportcard.com/report/github.com/ihexxa/randstr)
[](https://pkg.go.dev/github.com/ihexxa/randstr)
_Customizable random string generator in Go/Golang._
## Examples
Document is [here](https://pkg.go.dev/github.com/ihexxa/randstr).
**Note**: This library should NOT be used in security-critical system.
### Generate random strings with numbers/alphabets/alnums/candidates:
```go
import "github.com/ihexxa/randstr"
// customized generator
candidates := []string{"你", "好", "世", "界"}
randStr := randstr.New(candidates)
fmt.Println(randStr.Gen()) // output could be: 世世界你你你你好
fmt.Println(randStr.Alphabets())
fmt.Println(randStr.Numbers())
fmt.Println(randStr.Alnums())
```
### Generate fixed-length random strings:
```go
import "github.com/ihexxa/randstr"
candidates := []string{"你", "好", "世", "界"}
randStr := randstr.New(candidates)
randStr.SetLenFixed(true) // set sample size fixed
randStr.SetLenMax(8) // set sample size to 8
// above 3 lines can be replaced with randstr.NewRandstr(candidates, true, 8)
fmt.Println(randStr.Gen())
...
```
### Generate random slices:
```go
import "github.com/ihexxa/randstr"
randStr := randstr.New([]string{"你", "好", "世", "界"})
fmt.Println(randStr.GenSlice())
fmt.Println(randStr.AlphabetSlice())
fmt.Println(randStr.NumberSlice())
fmt.Println(randStr.AlnumSlice())
```
### License
MIT