]> Cypherpunks repositories - gostls13.git/commitdiff
slice, sort: correct triple of xorshift RNG
authorMeng Zhuo <mengzhuo@iscas.ac.cn>
Fri, 1 Nov 2024 01:51:08 +0000 (09:51 +0800)
committerMeng Zhuo <mengzhuo@iscas.ac.cn>
Sat, 2 Nov 2024 07:24:25 +0000 (07:24 +0000)
The original triple is `[13,17,5]` which don't existed in the Xorshift
RNG paper.
This CL use the right triple `[13,7,17]` for 64 bits RNG.

Fixes #70144

Change-Id: I3e3d475835980d9f28451ab73e3ce61eb2f1685e
Reviewed-on: https://go-review.googlesource.com/c/go/+/624295
Reviewed-by: Eli Bendersky <eliben@google.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: yunhao zhang <zhangyunhao116@gmail.com>
src/slices/sort.go
src/sort/sort.go

index f713ffe09473a727edcb959c4921add6831ebb4f..4f66e7bb3952f2f522a2f05c4e9146be1bd88e51 100644 (file)
@@ -180,8 +180,8 @@ type xorshift uint64
 
 func (r *xorshift) Next() uint64 {
        *r ^= *r << 13
-       *r ^= *r >> 17
-       *r ^= *r << 5
+       *r ^= *r >> 7
+       *r ^= *r << 17
        return uint64(*r)
 }
 
index 042ec4a8be79125c3ba60d8610bbc48a7112d303..b27ecabdd574680a979cedcb0eef5310662e7b76 100644 (file)
@@ -67,8 +67,8 @@ type xorshift uint64
 
 func (r *xorshift) Next() uint64 {
        *r ^= *r << 13
-       *r ^= *r >> 17
-       *r ^= *r << 5
+       *r ^= *r >> 7
+       *r ^= *r << 17
        return uint64(*r)
 }