note 86281 modified in function.rand by danbrown

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
A function to generate numbers of any length which contain  no identical digits side-by-side. i.e. 112233


<?php
function randomNumber($number_of_digits=null){
	for($x=0;$x<$number_of_digits;$x++){
		while(substr($num,strlen($num)-1,strlen($num)) == $r) $r = rand(0,9); 
		$new_number .= $r;
	}
	return $new_number;
}
?>

echo randomNumber(9);

// Output: 875438104

--was--
A function to generate numbers of any length which contain  no identical digits side-by-side. i.e. 112233

function randomNumber($number_of_digits=null){
	for($x=0;$x<$number_of_digits;$x++){
		while(substr($num,strlen($num)-1,strlen($num)) == $r) $r = rand(0,9); 
		$new_number .= $r;
	}
	return $new_number;
}

echo randomNumber(9);

// Output: 875438104

http://php.net/manual/en/function.rand.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.