Skip to content

Commit

Permalink
add gaussian distribution to the delay
Browse files Browse the repository at this point in the history
  • Loading branch information
jie committed Nov 17, 2023
1 parent d7e4e3d commit 805a229
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions util/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,27 @@ func GetCurrentTimestamp() string {
return time.Now().UTC().Format(time.RFC3339)
}

/*
func GetRandomLatency(min int, max int) int {
return min + rand.Intn(max-min)
}*/

func GetRandomLatency(min int, max int) int {
mean := float64(min+max) / 2
// Set the standard deviation so that ~99% of values fall within [min, max]
stddev := float64(max-min) / (2.575829 * 2)

for {
// Generate a normally distributed value
value := rand.NormFloat64()*stddev + mean

// Convert to int and check if within bounds
latency := int(value)
if latency >= min && latency < max {
return latency
}
// Regenerate if out of bounds
}
}

func CompressData(data []byte) ([]byte, error) {
Expand Down

0 comments on commit 805a229

Please sign in to comment.