https://github.com/twiny/dice
random string/int generator for the Go language
https://github.com/twiny/dice
golang random-int random-string
Last synced: about 1 month ago
JSON representation
random string/int generator for the Go language
- Host: GitHub
- URL: https://github.com/twiny/dice
- Owner: twiny
- License: mit
- Created: 2021-11-22T10:00:23.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-11-22T10:46:23.000Z (over 4 years ago)
- Last Synced: 2024-12-31T02:04:30.317Z (about 1 year ago)
- Topics: golang, random-int, random-string
- Language: Go
- Homepage:
- Size: 2.93 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Dice - random string/int utility for the Go language
This package contains a random string and int generator. It is a wrapper around the crypto/rand package.
**NOTE**: This package is provided "as is" with no guarantee. Use it at your own risk and always test it yourself before using it in a production environment. If you find any issues, please [create a new issue](https://github.com/twiny/dice/issues/new).
### Usage
```
go get github.com/twiny/dice
```
```go
package main
import (
"fmt"
"github.com/twiny/dice"
)
func main() {
for i := 0; i < 5; i++ {
j := dice.RandInt(1, 234567890)
fmt.Println(j)
}
//
for i := 0; i < 5; i++ {
j := dice.RandString(25)
fmt.Println(j)
}
//
fmt.Println("done :)")
}
// Output:
/*
159191458
40548335
112436247
211217306
137384292
EnZZq88MIR3sc4qUwJBHSkVmE
QFYze2dCr1UP0czV62xzWX3eP
UhIpkypBNe59LTZnQl9KkoxQk
tyffLFt6y2B9TsZB0H0eoqH0C
pCcAXLhqCOTN7w1htABSDEIfC
done :)
*/
```
### Benchmark
```
goos: darwin
goarch: amd64
pkg: dice
cpu: Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
BenchmarkRandString-4 1260508 945.0 ns/op 64 B/op 2 allocs/op
BenchmarkRandInt-4 1000000 1205 ns/op 56 B/op 4 allocs/op
PASS
ok dice 3.493s
```