summaryrefslogtreecommitdiff
path: root/internal/cpu/helpers.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/cpu/helpers.go')
-rw-r--r--internal/cpu/helpers.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/internal/cpu/helpers.go b/internal/cpu/helpers.go
new file mode 100644
index 0000000..9fcc6b9
--- /dev/null
+++ b/internal/cpu/helpers.go
@@ -0,0 +1,21 @@
+// Package cpu provides CPU stress testing with multiple algorithms and chaos modes.
+package cpu
+
+import "time"
+
+// helpers.go provides utility functions for randomization and timing.
+
+func (s *Stresser) randomIntensity() int {
+ s.mu.Lock()
+ defer s.mu.Unlock()
+ return s.rand.Intn(s.config.IntensityMax-s.config.IntensityMin+1) + s.config.IntensityMin
+}
+
+func (s *Stresser) getRandomMode() Mode {
+ return allModes[s.rand.Intn(len(allModes))]
+}
+
+func (s *Stresser) sleepWithJitter(minMs, maxMs int) {
+ ms := s.rand.Intn(maxMs-minMs+1) + minMs
+ time.Sleep(time.Duration(ms) * time.Millisecond)
+}