Jump to content
php.lv forumi

Optimizācija?


daGrevis

Recommended Posts

Tā, es tikko gribēju *facepalm* un pateikt: "Viss ģeniālais ir vienkāršs!" ...bet atcerējos kāpēc šis variants neder.

 

Pirmkārt iepazīstinu ar savu superīgo pārbaudes funkciju! =D (pārbaudām, vai vienmēr tiek izvadīti četri cipari)

 

<?

for($i = 0; $i < 1000000; $i++)
{

	$random = mt_rand(1000, 9999);

	if(strLen($random) !== 4)
	{

		echo 'Problems, Houston! =/';

	}

}

?>

 

Un tālāk, kāpēc neder. Nevar tikt izvadīts, piemēram, 0101, jo tas nav intervālā starp 1000 un 9999! =/

 

Nu ir vēl neveselīgais variants...

 

echo mt_rand(0, 9) . mt_rand(0, 9) . mt_rand(0, 9) . mt_rand(0, 9);

 

Bet tas patiešām ir hardcore! =D =D

Link to comment
Share on other sites

for ($i=0; $i<=10; $i++) {
$nr=rand(1,30)%2;
$str .= $nr ? chr(rand(65,90)) : chr(rand(48,57));
} 
echo $str;

 

Neatceros vai pats šo izgudroju. Bet scripts ģenerē burtus,cīparus.

Edited by Maaren
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...