Skip to content

Instantly share code, notes, and snippets.

@Shariar-Hasan
Created February 2, 2021 14:50
Show Gist options
  • Save Shariar-Hasan/ffb7c7019610701326f886a30bb03a72 to your computer and use it in GitHub Desktop.
Save Shariar-Hasan/ffb7c7019610701326f886a30bb03a72 to your computer and use it in GitHub Desktop.
random number generator using function both string and number
// genarate random number with specific digit using function
function randNumber(n){
return Math.floor((Math.random()*10**n)); //if you want n digit random number as a number
}
function randNumString(n){
return (Math.random()*10**n+" ").split('.')[0]; //if you want n digit random number as a string
}
randNumber(4); // calling the random number
randNumString(4); //calling the random nuber as a string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment