ISAAC is a cryptographically secure pseudorandom number generator (CSPRNG) and stream cipher designed by Robert J. Jenkins Jr. in 1996. This Go implementation provides both 32-bit and 64-bit versions of ISAAC, with a generic implementation that supports both types.
- Pure Go implementation
- Generic implementation supporting both
uint32
anduint64
types - Cryptographically secure
- Fast and efficient
- Thread-safe
- No external dependencies
- Fixed-size array state for better performance
go get github.com/lbbniu/isaac
package main
import (
"fmt"
"github.com/lbbniu/isaac"
)
func main() {
// Create a new ISAAC instance with uint32
rng := isaac.New[uint32]()
// Generate random numbers
for i := 0; i < 5; i++ {
fmt.Println(rng.Rand())
}
}
// Create a new ISAAC instance with uint64
rng := isaac.New[uint64]()
// Create a new ISAAC instance
rng := isaac.New[uint32]()
// Seed with a fixed-size array
var seed [isaac.Words]uint32
rng.Seed(seed)
// Create a new ISAAC instance
rng := isaac.New[uint32]()
// Get a batch of random numbers
var result [isaac.Words]uint32
rng.Refill(&result)
The implementation includes:
- Generic implementation in
isaac.go
with fixed-size array state - 32-bit specific implementation in
isaac32.go
- 64-bit specific implementation in
isaac64.go
- Comprehensive test coverage with test vectors from GNU Coreutils
ISAAC is designed to be cryptographically secure. However, please note:
- Always use a cryptographically secure seed
- Do not reuse the same seed for different purposes
- Consider using a more modern CSPRNG for new applications
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.