https://github.com/leonklingele/randomstring
Cryptographically secure random strings in Go
https://github.com/leonklingele/randomstring
crypto password random random-string secure
Last synced: 9 months ago
JSON representation
Cryptographically secure random strings in Go
- Host: GitHub
- URL: https://github.com/leonklingele/randomstring
- Owner: leonklingele
- License: unlicense
- Created: 2017-02-02T00:06:22.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2025-05-10T22:22:26.000Z (11 months ago)
- Last Synced: 2025-05-10T23:20:09.923Z (11 months ago)
- Topics: crypto, password, random, random-string, secure
- Language: Go
- Homepage:
- Size: 36.1 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Cryptographically secure random strings in Go

I was tired of so many Go apps and libraries being [modulo-biased](https://stackoverflow.com/a/10984975) when generating random strings.
Here's another library to generate cryptographically secure and unbiased strings.
Internally this library uses Go's [crypto/rand](https://golang.org/pkg/crypto/rand/) package which reads from the best random generator your system provides.
## tl;dr
```sh
# Install library
go get -u github.com/leonklingele/randomstring/v2
```
```go
// .. and use it. Generate a 30 character long string
s, err := randomstring.Generate(30, randomstring.CharsASCII)
```
```go
// You can even use your own alphabet "abc". Be careful though!
s, err := randomstring.Generate(30, "abc")
```
Supported alphabets:
- `randomstring.CharsNum`: Contains numbers from 0-9
- `randomstring.CharsAlpha`: Contains the full English alphabet: letters a-z and A-Z
- `randomstring.CharsAlphaNum`: Is a combination of CharsNum and CharsAlpha
- `randomstring.CharsASCII`: Contains all printable ASCII characters in code range [32, 126]