You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
roll:=1+rand.Intn(6) //nolint:gosec // G404: Use of weak random number generator (math/rand instead of crypto/rand) is ignored as this is not security-sensitive.
11
+
funcrolldice(rollsint) ([]int, error) {
12
+
ifrolls<=0 {
13
+
returnnil, errors.New("rolls must be positive")
14
+
}
16
15
17
-
varmsgstring
18
-
ifplayer:=r.PathValue("player"); player!="" {
19
-
msg=player+" is rolling the dice"
20
-
} else {
21
-
msg="Anonymous player is rolling the dice"
16
+
ifrolls==1 {
17
+
return []int{rollOnce()}, nil
22
18
}
23
-
log.Printf("%s, result: %d", msg, roll)
24
19
25
-
resp:=strconv.Itoa(roll) +"\n"
26
-
if_, err:=io.WriteString(w, resp); err!=nil {
27
-
log.Printf("Write failed: %v", err)
20
+
results:=make([]int, rolls)
21
+
fori:=0; i<rolls; i++ {
22
+
results[i] =rollOnce()
28
23
}
24
+
returnresults, nil
25
+
}
26
+
27
+
// rollOnce is the inner function — returns a random number 1–6.
28
+
funcrollOnce() int {
29
+
roll:=1+rand.Intn(6) //nolint:gosec // G404: Use of weak random number generator (math/rand instead of crypto/rand) is ignored as this is not security-sensitive.
0 commit comments