hw2

package
v0.0.0-...-afa3bba Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2019 License: Unlicense Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BirthdayParadox

func BirthdayParadox(numPeople, numTrials int) float64

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

func ComputePeriodLength(is []int) int

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

func Contains(is []int, j int) bool

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

func CountNumDigits(i int) int

CountNumDigits Take an integer and counts the number of digits. It ignores any minus sign

func CountNumDigitss

func CountNumDigitss(i int) int

CountNumDigitss Take an integer and counts the number of digits. It ignores any minus sign An elegant 1 line solution, but very inefficient!

func EuclidGCD

func EuclidGCD(a, b int) int

EuclidGCD is copied from Phillip's Go code files

func GenerateLinearCongruentialSequence

func GenerateLinearCongruentialSequence(seed, a, c, m int) []int

GenerateLinearCongruentialSequence returns an []int composed of generated random numbers It finishes as soon as a repeat is detected

func GenerateMiddleSquareSequence

func GenerateMiddleSquareSequence(seed, numDigits int) []int

GenerateMiddleSquareSequence returns an []int composed of generated random numbers It finishes as soon as a repeat is detected

func HasRepeat

func HasRepeat(is []int) bool

HasRepeat returns true if any of the elements in the slice are the same

func IsRelativePrime

func IsRelativePrime(i, j int) bool

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

func LinearCongruential(seed, a, c, m int) int

LinearCongruential return the next value of a Linear Conruential Generator Where Xnext <- (a*X +c) mod m

func MiddleSquare

func MiddleSquare(seed, numDigits int) int

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

func NewLinearCongruentialPRNG(seed, a, c, m int) func() int

NewLinearCongruentialPRNG returns a new Linear Conruential Generator random number generator function Where Xnext <- (a*X +c) mod m

func NewMiddleSquarePrng

func NewMiddleSquarePrng(seed, numDigits int) func() int

NewMiddleSquarePrng returns a new MiddleSquare random number generator function

func Pow10

func Pow10(i int) int

Pow10 returns an int of 10^i

func RandPairInRange

func RandPairInRange(from, to int) (int, int)

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

func RelativelyPrimeProbability(from, to, numTrials int) float64

RelativelyPrimeProbability the relative probability that two ints selected form a range are co-prime

func RunGCD

func RunGCD(from, to, numTrials int, gcd func(a, b int) int) time.Duration

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 TakeMiddlen

func TakeMiddlen(val, n int) int

TakeMiddlen Takes the middle n digits of val.

func TakeMiddlens

func TakeMiddlens(val, n int) int

TakeMiddlens Takes the middle n digits of val. We do the manipulation with a string

func TrivialGCD

func TrivialGCD(a, b int) int

TrivialGCD is copied from Phillip's Go code files

func WeightedDie

func WeightedDie() int

WeightedDie biases 3 to have a probability of .5

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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