Showing posts with label random no. Show all posts
Showing posts with label random no. Show all posts

Saturday 28 June 2014

How to get n digit random numers in php?

function generate_number_code( $length = 8 ) {
  $chars = "0123456789";
  $password = substr( str_shuffle( $chars ), 0, $length );
  return $password;
 }

JS get random Numbers

function getRandom(length) {
 var rand = Math.floor(Math.pow(10, length-1) + Math.random() * 9 * Math.pow(10, length-1));
 return rand;
}