This repository has moved to GitLab.



    Package fastrand implements a cryptographically secure pseudorandom number generator. The generator is seeded using the system's default entropy source, and thereafter produces random values via repeated hashing. As a result, fastrand can generate randomness much faster than crypto/rand, and generation cannot fail beyond a potential panic at init.

    The method used in this package is similar to the Fortuna algorithm, which is used in used in FreeBSD for /dev/urandom. This package uses techniques that are known to be secure, however the exact implementation has not been heavily reviewed by cryptographers.



    This section is empty.


    View Source
    var Reader io.Reader

      Reader is a global, shared instance of a cryptographically strong pseudo- random generator. It uses blake2b as its hashing function. Reader is safe for concurrent use by multiple goroutines.


      func BigIntn

      func BigIntn(n *big.Int) *big.Int

        BigIntn returns a uniform random *big.Int in [0,n). It panics if n <= 0.

        func Bytes

        func Bytes(n int) []byte

          Bytes is a helper function that returns n bytes of random data.

          func Intn

          func Intn(n int) int

            Intn returns a uniform random int in [0,n). It panics if n <= 0.

            func Perm

            func Perm(n int) []int

              Perm returns a random permutation of the integers [0,n).

              func Read

              func Read(b []byte)

                Read is a helper function that calls Reader.Read on b. It always fills b completely.

                func Uint64n

                func Uint64n(n uint64) uint64

                  Uint64n returns a uniform random uint64 in [0,n). It panics if n == 0.


                  This section is empty.

                  Source Files