Go package provides math/rand.Source64
implementation based on crypto/rand
.
- Simple API.
- Dependency-free.
- Clean and tested code.
Go version 1.19+
go get github.com/cristalhq/cryptorand
r := rand.New(cryptorand.Source)
m := map[string]struct{}{}
for i := 0; i < 100; i++ {
s := fmt.Sprint(r.Float64())
m[s] = struct{}{}
}
fmt.Printf("Have %d unique floats", len(m))
// Output:
// Have 100 unique floats
See examples: example_test.go.
See these docs for more details.