Categories

random number function

a random number function

function rand_num($lowest,$highest)
{
$rand_number = round(rand($lowest,$highest));
echo $rand_number;
}

Octal / Decimal conversions

Octal to decimal conversion first
<?php
print(decoct(255) . “<br>”);
?>

and this is the octal to decimal version
<?php
print(octdec(“377″));
?>

Hexadecimal / Decimal conversion

Decimal to hexadecimal first

<?php
print(dechex(255) . “<br>”);
?>

and then hexadecimal to decimal

<?php
print(hexdec(“FF”));
?>

Decimal to binary conversion

<?php
print(decbin(255) . “<br>”);
?>

Binary to decimal conversion

<?php
print(bindec(“1111″));
?>

Random number example

<?php
//produce random numbers
srand((double)microtime()*1000000);
//number between 1 and 100
$random_number1 = rand(1,100);
echo (“$random_number1<br>”);
//between 1 and 50 this time
$random_number2 = rand(1,50);
echo (“$random_number2<br>”);
//finally between 55 and 95
$random_number3 = rand(55,95);
echo (“$random_number3″);
?>