Documentation ¶
Index ¶
- func BirthdayParadox(numPeople, numTrials int) float64
- func ComputePeriodLength(is []int) int
- func Contains(is []int, j int) bool
- func CountNumDigits(i int) int
- func CountNumDigitss(i int) int
- func EuclidGCD(a, b int) int
- func GenerateLinearCongruentialSequence(seed, a, c, m int) []int
- func GenerateMiddleSquareSequence(seed, numDigits int) []int
- func HasRepeat(is []int) bool
- func IsRelativePrime(i, j int) bool
- func LinearCongruential(seed, a, c, m int) int
- func MiddleSquare(seed, numDigits int) int
- func NewLinearCongruentialPRNG(seed, a, c, m int) func() int
- func NewMiddleSquarePrng(seed, numDigits int) func() int
- func Pow10(i int) int
- func RandPairInRange(from, to int) (int, int)
- func RelativelyPrimeProbability(from, to, numTrials int) float64
- func RunGCD(from, to, numTrials int, gcd func(a, b int) int) time.Duration
- func TakeMiddlen(val, n int) int
- func TakeMiddlens(val, n int) int
- func TrivialGCD(a, b int) int
- func WeightedDie() int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BirthdayParadox ¶
BirthdayParadox takes a number of people numPeople, a number of trials numTrials, and returns the % of time that at least 2 people have the same birthday See https://en.wikipedia.org/wiki/Birthday_problem
func ComputePeriodLength ¶
ComputePeriodLength takes a slice as input and returns the length (period) of the first repeating sequence If no repeats are found, it returns 0
func Contains ¶
Contains tells whether a contains x. Has Repeat is very slow. When creating a sequence, simply checking whether the element being added to the sequence already exists is enough to detect a cycle.
func CountNumDigits ¶
CountNumDigits Take an integer and counts the number of digits. It ignores any minus sign
func CountNumDigitss ¶
CountNumDigitss Take an integer and counts the number of digits. It ignores any minus sign An elegant 1 line solution, but very inefficient!
func GenerateLinearCongruentialSequence ¶
GenerateLinearCongruentialSequence returns an []int composed of generated random numbers It finishes as soon as a repeat is detected
func GenerateMiddleSquareSequence ¶
GenerateMiddleSquareSequence returns an []int composed of generated random numbers It finishes as soon as a repeat is detected
func IsRelativePrime ¶
IsRelativePrime returns true if the 2 ints are coprime, aka relatively prime See https://en.wikipedia.org/wiki/Coprime_integers and http://mathworld.wolfram.com/RelativelyPrime.html
func LinearCongruential ¶
LinearCongruential return the next value of a Linear Conruential Generator Where Xnext <- (a*X +c) mod m
func MiddleSquare ¶
MiddleSquare squares the input and then takes the numDigits digits from the middle of the result The input must contain an even number of digits
func NewLinearCongruentialPRNG ¶
NewLinearCongruentialPRNG returns a new Linear Conruential Generator random number generator function Where Xnext <- (a*X +c) mod m
func NewMiddleSquarePrng ¶
NewMiddleSquarePrng returns a new MiddleSquare random number generator function
func RandPairInRange ¶
RandPairInRange Returns a pair of unique random ints in the range specified inclusive of the requested limits. The limits may be specified in any order
func RelativelyPrimeProbability ¶
RelativelyPrimeProbability the relative probability that two ints selected form a range are co-prime
func RunGCD ¶
RunGCD runs a randomized test of a GCD function, and calculates the total time that the function takes, averaged over the total number of trials
func TakeMiddlens ¶
TakeMiddlens Takes the middle n digits of val. We do the manipulation with a string
Types ¶
This section is empty.