Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/susisu/go-tf-random
A splittable pseudorandom number generator based on the Threefish block cipher
https://github.com/susisu/go-tf-random
Last synced: 2 days ago
JSON representation
A splittable pseudorandom number generator based on the Threefish block cipher
- Host: GitHub
- URL: https://github.com/susisu/go-tf-random
- Owner: susisu
- License: mit
- Created: 2023-03-04T06:37:00.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-03-12T13:22:13.000Z (almost 2 years ago)
- Last Synced: 2024-11-06T04:41:32.267Z (about 2 months ago)
- Language: Go
- Homepage: https://pkg.go.dev/github.com/susisu/go-tf-random
- Size: 30.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-tf-random
[![CI](https://github.com/susisu/go-tf-random/workflows/CI/badge.svg)](https://github.com/susisu/go-tf-random/actions?query=workflow%3ACI)
A splittable pseudorandom number generator using [the Threefish block cipher](https://en.wikipedia.org/wiki/Threefish).
- [The original Haskell implementation](https://hackage.haskell.org/package/tf-random)
- [My JavaScript/TypeScript implementation](https://github.com/susisu/tf-random.js)This module is based on the JS/TS implementation, and there are some minor differences (including bug fixes) compared to the original one.
## Usage
Use `go get` to install:
``` shell
go get github.com/susisu/go-tf-random
```go-tf-random exports a generator implementation `TFGen` that allows you to generate random uint32 values.
To generate random values of other numeric types, you can use [go-random](https://github.com/susisu/go-random).``` go
package mainimport (
"fmt"random "github.com/susisu/go-random/uint32"
tf_random "github.com/susisu/go-tf-random"
)func main() {
g1 := tf_random.NewTFGen(42, 42, 42, 42)
v1 := random.Float64(g1)
fmt.Printf("%f\n", v1)
}
```And most importantly, `TFGen` can be split to create new generators that are independent of the original one.
These new generators can be safely passed around to other functions and goroutines, which allows you to make your code more predictable.``` go
func main() {
// ...g2 := g1.Split()
v2 := random.Float64(g2)
fmt.Printf("%f\n", v2)
}
```## Performance
Sadly, `TFGen` isn't that fast due to its relatively complex computations.
Use it only in non-performance-critical code, or help me improve its performance!```
goos: darwin
goarch: arm64
pkg: github.com/susisu/go-tf-random
BenchmarkTFGen_Uint32-10 61052778 18.85 ns/op 8 B/op 0 allocs/op
BenchmarkMathRand-10 526618652 2.341 ns/op 0 B/op 0 allocs/op
```## License
[MIT License](http://opensource.org/licenses/mit-license.php)
## Author
Susisu ([GitHub](https://github.com/susisu), [Twitter](https://twitter.com/susisu2413))