From: Ken Thompson Date: Sun, 16 Nov 2008 21:02:47 +0000 (-0800) Subject: random permutation function X-Git-Tag: weekly.2009-11-06~2718 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=2567c073ea230cf96078477be117f07a16e93470;p=gostls13.git random permutation function func perm(n int) *map[int]int R=r OCL=19340 CL=19340 --- diff --git a/src/lib/rand.go b/src/lib/rand.go index 8619cc48c2..ef122d4a92 100644 --- a/src/lib/rand.go +++ b/src/lib/rand.go @@ -14,6 +14,7 @@ package rand // urand32 - return random uint32 // nrand, nrand31, nrand63 - return 0 <= random < n // frand, frand64, frand32 - return 0 <= random float, float64, float32 < 1 +// perm gives a random permutation map[int]int const ( @@ -162,6 +163,22 @@ frand() float return float(frand64()) } +export func +perm(n int) *map[int]int +{ + m := new(map[int]int); + for i:=0; i