perm

package
v0.0.0-...-9e3c222 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2016 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package perm provides a generator object which can be used to iterate through a permutation of a given range in constant space.

The current implementation uses a Feistel network, with blake2b as the round function. Note that since the entropy seeding the round function is typically far smaller than the full permutation space, the generator cannot enumerate the full space in such cases. For example, even a 128-bit key can only enumerate the permutation space of 34 elements, since 2^128 < 35!. This is a known limitation of Feistel networks.

For small n, it may be more efficient to enumerate [0,n) and permute the values in-place using the well-known Fisher-Yates algorithm (this is what math/rand.Perm uses). For convenience, such a function is provided in this package as well.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FisherYates

func FisherYates(n int) []int

FisherYates returns a pseudorandom permutation of the integers [0,n).

func NewGenerator

func NewGenerator(numElems, seed uint32) *feistelGenerator

NewGenerator returns a new Feistel network-based permutation generator.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL