Skip to content

Commit c0f4e15

Browse files
authored
Ever increasing Trend with Noise generator values (#34)
1 parent 9d6d514 commit c0f4e15

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

datamodel/noise/generator.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,18 @@ func PerlinNoise(offset, alpha, beta float64, scale float64) Generator {
107107
// - noiseScale: The amplitude of the random noise added to the trend.
108108
// Determines the intensity of the noise.
109109
func TrendWithNoise(startValue, step, noiseScale float64) func() float64 {
110-
value := startValue
110+
prevValue := startValue
111111
return func() float64 {
112-
value += step
112+
newValue := prevValue + step
113113
// nolint:gosec
114114
// It's okay to use the default random number generator here.
115115
noise := (rand.Float64()*2 - 1) * noiseScale
116116
if step < 0 {
117-
return min(value, value+noise)
117+
newValue = min(newValue, newValue+noise)
118118
}
119-
return max(value, value+noise)
119+
newValue = max(newValue, newValue+noise)
120+
prevValue = newValue
121+
return newValue
120122
}
121123
}
122124

doc/images/trend_with_noise.png

-57.3 KB
Loading

0 commit comments

Comments
 (0)