rand

package module
v0.0.0-...-9bd989e Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2017 License: CC0-1.0 Imports: 4 Imported by: 3

Documentation

Overview

Package rand implements the Borland C/C++ pseudo-random number generator algorithm [1] to generate random Complex128 numbers in the range (-2,-2i) to (2,2i).

[1]: https://en.wikipedia.org/wiki/Linear_congruential_generator#Parameters_in_common_use

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs(x float64) float64

func AddUint64

func AddUint64(addr *uint64, delta uint64) (new, old uint64)

Function AddUint64 returns the new and old value after adding delta, this function is executed atomically.

func GetSeed

func GetSeed() (a int64, err error)

Function GetSeed returns a 64-bit NIST SP800-90B & C compliant random value from a call to RDSEED. If RDSEED is not available or not able to generate a random number in 1024 tries then crypto/rand Read is used to create the seed.

Types

type ComplexRNG

type ComplexRNG struct {
	// contains filtered or unexported fields
}

func NewComplexRNG

func NewComplexRNG(seed int64) (r ComplexRNG, err error)

Function NewComplexRnd returns a new ComplexRNG with the seed set to seed. If seed is set to 0 NewComplexRNG will use GetSeed to set seed. Methods on NewComplexRndThis are NOT Thread Safe, initiate one ComplexRNG per goroutine.

func (*ComplexRNG) Complex128

func (rng *ComplexRNG) Complex128() complex128

Complex128 returns a pseudo-random complex128 where the imag and real part is in the range -2 to 2.

func (*ComplexRNG) ComplexRand

func (rng *ComplexRNG) ComplexRand() complex128

ComplexRand returns a pseudo-random complex128 where the imag and real part is in the range -2 to 2. The random values are evenly distributed between all possible floats in the specified range, this makes it very lightly to get a very small number very close to 0 as the density of valid floats are much denser near 0. Eg. The probability of getting a real part that is over 1 or lower than -1 is about 0.1% and the probability of getting a real part in between 1.0e-150 and -1.0e-150 is about 50%.

type ComplexRNGts

type ComplexRNGts struct {
	// contains filtered or unexported fields
}

func NewComplexRNGts

func NewComplexRNGts(seed int64) (r ComplexRNGts, err error)

Function NewComplexRndts returns a new ComplexRNG with the seed set to seed. If seed is set to 0 NewComplexRNGts will use GetSeed to set seed. All methods on NewComplexRndts have sacrificed speed for thread safety. Equivalent methods on NewComplexRNG are about 5X faster.

func (*ComplexRNGts) Complex128

func (rng *ComplexRNGts) Complex128() complex128

Complex128 returns a pseudo-random complex128 where the imag and real part is in the range -2 to 2.

func (*ComplexRNGts) ComplexRand

func (rng *ComplexRNGts) ComplexRand() complex128

ComplexRand returns a pseudo-random complex128 where the imag and real part is in the range -2 to 2. The random values are evenly distributed between all possible floats in the specified range, this makes it very lightly to get a very small number very close to 0 as the density of valid floats are much denser near 0. Eg. The probability of getting a real part that is over 1 or lower than -1 is about 0.1% and the probability of getting a real part in between 1.0e-150 and -1.0e-150 is about 50%.

Jump to

Keyboard shortcuts

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