https://github.com/ernsheong/grand
Grand is a Go random string generator
https://github.com/ernsheong/grand
go golang random random-string string-generator
Last synced: 27 days ago
JSON representation
Grand is a Go random string generator
- Host: GitHub
- URL: https://github.com/ernsheong/grand
- Owner: ernsheong
- License: mit
- Created: 2017-09-02T07:23:46.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2021-02-19T09:31:37.000Z (almost 5 years ago)
- Last Synced: 2025-12-16T02:42:01.467Z (about 2 months ago)
- Topics: go, golang, random, random-string, string-generator
- Language: Go
- Size: 5.86 KB
- Stars: 11
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Grand
[](http://godoc.org/github.com/ernsheong/grand)
Grand is a Go random string generator.
## Installation
`go get github.com/ernsheong/grand`
## Usage
1. **IMPORTANT.** Seed `rand` first to ensure you don't get the same string on every code run (initialize):
```go
rand.Seed(time.Now().UTC().UnixNano())
```
or
```go
rand.Seed(time.Now().Unix())
```
1. Generate your random string, given a length parameter `n`:
```go
grand.GenerateRandomString(32)
// returns "qzrWbaoLTVpQoottZyPFfNOoMioXHRuF"
```
1. Generate random string from other character sets:
```go
gen := grand.NewGenerator(grand.CharSetBase62)
gen.GenerateRandomString(20)
// returns "q3rWba2LTVpQ4ottZyPv"
```
## Concurrency
From the `math/rand` [docs](https://golang.org/pkg/math/rand/):
> The default Source is safe for concurrent use by multiple goroutines
`grand` uses the default Source, and hence is safe to be called from multiple goroutines, at a slight performance penalty. See https://stackoverflow.com/a/31832326/1161743 for details.
## Credits
I claim no credit for the generation logic. It's originally from user icza in https://stackoverflow.com/a/31832326/1161743.