summaryrefslogtreecommitdiff
path: root/Settings/Distribution.go
blob: fc8ae13d2554f31675aa5a137ebad2f0a12192cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package settings

import "math/rand"

type distributionOptions struct {
	// The chance of a value to be defaulted by zero
	RandomisationChance float64
	// The song start point will be between [0; len(song) * MaxPointPercent]
	MaxPointPercent float64
	// All the values less than this param will be defaulted to zero

	StartSnapPercent float64
}

func (base distributionOptions) GetDistributedInt(dur int) int {
	if rand.Float64() < base.RandomisationChance {
		return 0
	}
	var random = rand.Float64() * base.MaxPointPercent
	if random >= 1 {
		panic("Random is greater than 1")
	}
	var randomDur = int(random * float64(dur))
	if randomDur <= int(base.StartSnapPercent * float64(dur)) {
		return 0
	}
	return randomDur
}