Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rand: add methods to allow greater control over PCGSource #30

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions rand/rng.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ func (pcg *PCGSource) Uint64() uint64 {
return bits.RotateLeft64(pcg.high^pcg.low, -int(pcg.high>>58))
}

// Seed128 sets both the high and low bits of the generator state to the provided values.
func (pcg *PCGSource) Seed128(high, low uint64) {
pcg.high = high
pcg.low = low
}

// State returns the high and low bits of the generator state.
func (pcg *PCGSource) State() (high, low uint64) {
return pcg.high, pcg.low
}

func (pcg *PCGSource) add() {
var carry uint64
pcg.low, carry = bits.Add64(pcg.low, incLow, 0)
Expand Down