Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kennychenfight/randstr
Generate random string very faster
https://github.com/kennychenfight/randstr
go
Last synced: 3 days ago
JSON representation
Generate random string very faster
- Host: GitHub
- URL: https://github.com/kennychenfight/randstr
- Owner: KennyChenFight
- License: apache-2.0
- Created: 2021-04-26T10:00:17.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-04-26T10:19:19.000Z (over 3 years ago)
- Last Synced: 2024-06-20T16:32:07.812Z (4 months ago)
- Topics: go
- Language: Go
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Go Reference](https://pkg.go.dev/badge/github.com/KennyChenFight/golib.svg)](https://pkg.go.dev/github.com/KennyChenFight/randstr)
# randstr
generate random string very faster.The code is based on this awesome StackOverflow answer by [icza](https://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-go).
## How to use
### install
`go get github.com/KennyChenFight/randstr`
### Example
```go
package mainimport (
"fmt"
"github.com/KennyChenFight/randstr"
)func main() {
const randomStrLength = 6
generator := randstr.NewFastGenerator(randstr.CharSetEnglishAlphabet)
fmt.Println(generator.GenerateRandomStr(randomStrLength))
}
```
You can reference example folder.## Benchmark
```bash
goos: windows
goarch: amd64
pkg: github.com/KennyChenFight/randstr
cpu: Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz
BenchmarkFastGenerator_GenerateRandomStr_EnglishAlphabet
BenchmarkFastGenerator_GenerateRandomStr_EnglishAlphabet-8 27867314 42.19 ns/op 1 allocs/op
BenchmarkFastGenerator_GenerateRandomStr_EnglishAlphabetLowercase
BenchmarkFastGenerator_GenerateRandomStr_EnglishAlphabetLowercase-8 29626336 41.15 ns/op 1 allocs/op
BenchmarkFastGenerator_GenerateRandomStr_EnglishAlphabetUppercase
BenchmarkFastGenerator_GenerateRandomStr_EnglishAlphabetUppercase-8 29051328 42.44 ns/op 1 allocs/op
BenchmarkFastGenerator_GenerateRandomStr_EnglishAlphabetBase62
BenchmarkFastGenerator_GenerateRandomStr_EnglishAlphabetBase62-8 41708664 29.78 ns/op 1 allocs/op
BenchmarkFastGenerator_GenerateRandomStr_EnglishAlphabetBase64
BenchmarkFastGenerator_GenerateRandomStr_EnglishAlphabetBase64-8 14275873 86.11 ns/op 1 allocs/op
```## Original generate random string benchmark
You can reference original folder.