@@ -8,6 +8,10 @@ import (
88 "time"
99)
1010
11+ // seededRand is a package-level random source seeded at startup.
12+ // math/rand is appropriate here — simulation output is not security-sensitive.
13+ var seededRand = rand .New (rand .NewSource (time .Now ().UnixNano ())) //nolint:gosec
14+
1115// SimulateResolution returns a synthetic DNS result without performing any
1216// network I/O. Common subdomain prefixes resolve ~90% of the time; everything
1317// else uses the supplied hitRate (0-100).
@@ -21,20 +25,20 @@ func SimulateResolution(domain string, hitRate int, verbose bool) bool {
2125 for _ , sub := range commonSubdomains {
2226 if strings .HasPrefix (domain , sub + "." ) {
2327 if verbose {
24- fakeTiming := time .Duration (50 + rand .Intn (200 )) * time .Millisecond
25- fakeIP := fmt .Sprintf ("192.168.%d.%d" , rand .Intn (255 ), 1 + rand .Intn (254 ))
28+ fakeTiming := time .Duration (50 + seededRand .Intn (200 )) * time .Millisecond
29+ fakeIP := fmt .Sprintf ("192.168.%d.%d" , seededRand .Intn (255 ), 1 + seededRand .Intn (254 ))
2630 fmt .Fprintf (os .Stderr , "Resolved (SIMULATED): %s (IP: %s) in %s\n " , domain , fakeIP , fakeTiming )
2731 }
28- return rand .Intn (100 ) < 90
32+ return seededRand .Intn (100 ) < 90
2933 }
3034 }
3135
32- result := rand .Intn (100 ) < hitRate
36+ result := seededRand .Intn (100 ) < hitRate
3337
3438 if verbose {
35- fakeTiming := time .Duration (100 + rand .Intn (500 )) * time .Millisecond
39+ fakeTiming := time .Duration (100 + seededRand .Intn (500 )) * time .Millisecond
3640 if result {
37- fakeIP := fmt .Sprintf ("10.%d.%d.%d" , rand .Intn (255 ), rand .Intn (255 ), 1 + rand .Intn (254 ))
41+ fakeIP := fmt .Sprintf ("10.%d.%d.%d" , seededRand .Intn (255 ), seededRand .Intn (255 ), 1 + seededRand .Intn (254 ))
3842 fmt .Fprintf (os .Stderr , "Resolved (SIMULATED): %s (IP: %s) in %s\n " , domain , fakeIP , fakeTiming )
3943 } else {
4044 fmt .Fprintf (os .Stderr , "Failed to resolve (SIMULATED): %s (Error: no such host) in %s\n " , domain , fakeTiming )
0 commit comments