]> Cypherpunks repositories - gostls13.git/commit
math/rand: add Shuffle
authorJosh Bleecher Snyder <josharian@gmail.com>
Wed, 26 Jul 2017 00:53:30 +0000 (17:53 -0700)
committerIan Lance Taylor <iant@golang.org>
Fri, 8 Sep 2017 13:03:02 +0000 (13:03 +0000)
commita2dfe5d278eae0864397a046a8206342a426d2bd
treea8020e62a551f27ccdba084a667a19c5ac48de0d
parent32e117d971eb4f802f27b98a0f13b7d9fc2d73fb
math/rand: add Shuffle

Shuffle uses the Fisher-Yates algorithm.

Since this is new API, it affords us the opportunity
to use a much faster Int31n implementation that mostly avoids division.
As a result, BenchmarkPerm30ViaShuffle is
about 30% faster than BenchmarkPerm30,
despite requiring a separate initialization loop
and using function calls to swap elements.

Fixes #20480
Updates #16213
Updates #21211

Change-Id: Ib8956c4bebed9d84f193eb98282ec16ee7c2b2d5
Reviewed-on: https://go-review.googlesource.com/51891
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/math/rand/example_test.go
src/math/rand/rand.go
src/math/rand/rand_test.go