28 lines
615 B
Go
28 lines
615 B
Go
package pwgenerator
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"encoding/binary"
|
|
)
|
|
|
|
// Int63 is used to interface as a *(math/rand).Rand but backed with a cryptographically sound generation.
|
|
func (c *cryptoShuffler) Int63() (i int64) {
|
|
|
|
var b [8]byte
|
|
|
|
_, _ = rand.Read(b[:])
|
|
|
|
// Mask is used to ensure a positive number.
|
|
i = int64(binary.LittleEndian.Uint64(b[:]) & (1<<63 - 1))
|
|
|
|
return
|
|
}
|
|
|
|
// Seed is used to interface as a *(math/rand).Rand.
|
|
func (c *cryptoShuffler) Seed(_ int64) {
|
|
|
|
// It's 100% OK that this is a no-op because we seed from the crypto methodology itself within cryptoShuffler.Int63 on each call.
|
|
|
|
return
|
|
}
|