Hello,
I am trying to create a function that takes a parameter (n) and generates a random number of n digits.
I found a similar function on stack overflow that looks like this:
Math.floor(100000 + Math.random() * 900000)
. This creates a random 6 digit number every time.
I have attempted to write my own function like this:
const randomNDigitsNumber = (n) => Math.floor(Math.pow(1, n) + Math.random() * Math.pow(9, n));
My function works the majority of the time but it is occasionally one digit short?
Any ideas what I’m doing wrong?