DENIAL OF RESPONSIBILITY:
JavaScript math.rand () is not cryptographically secure, which means that it should NOT be used to generate random numbers associated with a password, PIN, and / or gambling. If this is your use case, please use the web crypto API instead!
If the digit 0 is not included (1-9):
function randInt() { return Math.floor((Math.random()*9)+1); }
If the digit 0 (0-9) is turned on:
function randIntWithZero() { return Math.floor((Math.random()*10)); }
source share