Is there a Cryptographically Secure Pseudo-Random Number Generator (CSPRNG) in Javascript?
I know I can generate a pseudo-random number using
Math.random();
function getRandomInt(max) {
return Math.floor(Math.random() * Math.floor(max));
}
In Python I would use secrets() instead of random().
import secrets alphabet = string.ascii_letters + string.digits password = ''.join(secrets.choice(alphabet) for i in range(8))
In Go I would use the crypto.rand package instead of the math/rand package.
package main
import (
"bytes"
"crypto/rand"
"fmt"
)
func main() {
c := 10
b := make([]byte, c)
_, err := rand.Read(b)
if err != nil {
fmt.Println("error:", err)
return
}
fmt.Println(bytes.Equal(b, make([]byte, c)))
}
Is there an equivalent in javascript?