From 20a3031ddeef3b057cd935d145c5aaa3a7030d3c Mon Sep 17 00:00:00 2001 From: DeedleFake Date: Mon, 4 Apr 2022 23:11:50 -0400 Subject: [PATCH 1/3] rand: add methods to allow greater control over `PCGSource` For golang/go#49934. --- rand/rng.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/rand/rng.go b/rand/rng.go index 17cee105f..a054df558 100644 --- a/rand/rng.go +++ b/rand/rng.go @@ -58,6 +58,17 @@ func (pcg *PCGSource) Uint64() uint64 { return bits.RotateLeft64(pcg.high^pcg.low, -int(pcg.high>>58)) } +// Seed64 sets both the high and low bits of the generator state to the provided values. +func (pcg *PCGSource) Seed64(high, low uint64) { + pcg.high = high + pcg.low = low +} + +// PCG returns the high and low bits of the generator state. +func (pcg *PCGSource) PCG() (high, low uint64) { + return pcg.high, pcg.low +} + func (pcg *PCGSource) add() { var carry uint64 pcg.low, carry = bits.Add64(pcg.low, incLow, 0) From 776a471211c5c0ec1a7d4bc4ebbd607f9cda5a2e Mon Sep 17 00:00:00 2001 From: DeedleFake Date: Wed, 6 Apr 2022 10:44:49 -0400 Subject: [PATCH 2/3] rand: rename `PCGSource.PCG` to `PCGSource.State` --- rand/rng.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rand/rng.go b/rand/rng.go index a054df558..46a833a6d 100644 --- a/rand/rng.go +++ b/rand/rng.go @@ -64,8 +64,8 @@ func (pcg *PCGSource) Seed64(high, low uint64) { pcg.low = low } -// PCG returns the high and low bits of the generator state. -func (pcg *PCGSource) PCG() (high, low uint64) { +// State returns the high and low bits of the generator state. +func (pcg *PCGSource) State() (high, low uint64) { return pcg.high, pcg.low } From 7f2d9084acbfd75201d16a951289c37ae33987b8 Mon Sep 17 00:00:00 2001 From: DeedleFake Date: Mon, 18 Apr 2022 11:48:55 -0400 Subject: [PATCH 3/3] rand: rename `PCGSource.Seed64` to `PCGSource.Seed128` --- rand/rng.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rand/rng.go b/rand/rng.go index 46a833a6d..5de0f9bd1 100644 --- a/rand/rng.go +++ b/rand/rng.go @@ -58,8 +58,8 @@ func (pcg *PCGSource) Uint64() uint64 { return bits.RotateLeft64(pcg.high^pcg.low, -int(pcg.high>>58)) } -// Seed64 sets both the high and low bits of the generator state to the provided values. -func (pcg *PCGSource) Seed64(high, low uint64) { +// 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 }