make RNG inclusive on both ends

This commit is contained in:
2021-08-18 18:24:14 +03:00
parent d5e973ae66
commit 2b50356acf
+2 -2
View File
@@ -39,8 +39,8 @@ func RandomHandler(w http.ResponseWriter, req *http.Request) {
min := 1 min := 1
// seed the default source using the current time in unix nanosecond format // seed the default source using the current time in unix nanosecond format
rand.Seed(time.Now().UnixNano()) rand.Seed(time.Now().UnixNano())
// generate random number between min and `max` // generate random number between min and max [min, max]
num := rand.Intn(int(max)-min) + min num := rand.Intn(int(max+1)-min) + min
// find the random kot document and store it in the `kot` variable // find the random kot document and store it in the `kot` variable
err = db.Kots.FindOne(db.Ctx, bson.M{"id": num}).Decode(&kot) err = db.Kots.FindOne(db.Ctx, bson.M{"id": num}).Decode(&kot)