tailscale/util/rands
James Tucker 24bac27632 util/rands: add Shuffle and Perm functions with on-stack RNG state
The new math/rand/v2 package includes an m-local global random number
generator that can not be reseeded by the user, which is suitable for
most uses without the RNG pools we have in a number of areas of the code
base.

The new API still does not have an allocation-free way of performing a
seeded operations, due to the long term compiler bug around interface
parameter escapes, and the Source interface.

This change introduces the two APIs that math/rand/v2 can not yet
replace efficiently: seeded Perm() and Shuffle() operations. This
implementation chooses to use the PCG random source from math/rand/v2,
as with sufficient compiler optimization, this source should boil down
to only two on-stack registers for random state under ideal conditions.

Updates #17243

Signed-off-by: James Tucker <james@tailscale.com>
2024-02-09 15:19:27 -08:00
..
cheap.go util/rands: add Shuffle and Perm functions with on-stack RNG state 2024-02-09 15:19:27 -08:00
cheap_test.go util/rands: add Shuffle and Perm functions with on-stack RNG state 2024-02-09 15:19:27 -08:00
rands.go util/rands: add package with HexString func 2023-09-05 09:17:21 -07:00
rands_test.go util/rands: add package with HexString func 2023-09-05 09:17:21 -07:00