NShiftKey-Rule-Guide logo NShiftKey-Rule-Guide

1. Vulnerability Description

2. How to check vulnerability

Check to import and use math/rand with the random package.

3. Vulnerability Countermeasure

The crypto/rand package implements and uses a cryptographically secure random number generator. The crypto/rand package can be used to prevent the vulnerability.

4. Sample Code

package main

import (
    "fmt"
    "time"
    "math/rand"
)

func main() {
    rand.Seed(time.Now().UnixNano())
    fmt.Println(rand.Intn(100))
}
package main

import (
    ""crypto/rand""
    ""fmt""
    ""math/big""
)

func main() {
    n, err := rand.Int(rand.Reader, big.NewInt(100))
    if err != nil {
        panic(err)
    }
    fmt.Println(n)
}