note 25079 modified in function.floor by danbrown
| From: | danbrown@php.net | Date: | Thu, 10 Mar 2011 15:23:56 +0000 |
| Subject: | note 25079 modified in function.floor by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-177769@lists.php.net to get a copy of this message | ||
mathematical functions lack a floating point version of the modulo operation, which returns the
difference between the floor() of the argument and the argument itself:
<?php
function fmod($value) {
return $value - floor($value);
}
?>
Very useful with trigonometric functions to reduce the angle argument to a circle that includes
angle 0.
Useful also to reduce an arbitrarily large floating point value into an entropy source, by first
transforming this value into a pair using logarithm functions with distinct bases (add 1 if the
function can return 0, to avoid floating point errors with logarithms!):
<?php
$f = 1 + @disk_free_space("/tmp");
$r = (int)(fmod(Log($f)) * 0x7FFFFFFF)
^ (int)(fmod(Log10($f)) * 0x7FFFFFFF)
?>
Then $r can be used as a good entropy source, if the free space in your temporary folder used by PHP
is constantly evolving within a large range of values.
You can combine this value by xoring it with other values such as time(), (int)microtime(),
ip2long($_SERVER['REMOTE_ADDR'], $_SERVER['REMOTE_PORT'], getmypid(), ...
--was--
mathematical functions lack a floating point version of the modulo operation, which returns the
difference between the floor() of the argument and the argument itself:
function fmod($value) {
return $value - floor($value);
}
Very useful with trigonometric functions to reduce the angle argument to a circle that includes
angle 0.
Useful also to reduce an arbitrarily large floating point value into an entropy source, by first
transforming this value into a pair using logarithm functions with distinct bases (add 1 if the
function can return 0, to avoid floating point errors with logarithms!):
$f = 1 + @disk_free_space("/tmp");
$r = (int)(fmod(Log($f)) * 0x7FFFFFFF)
^ (int)(fmod(Log10($f)) * 0x7FFFFFFF)
Then $r can be used as a good entropy source, if the free space in your temporary folder used by PHP
is constantly evolving within a large range of values.
You can combine this value by xoring it with other values such as time(), (int)microtime(),
ip2long($_SERVER['REMOTE_ADDR'], $_SERVER['REMOTE_PORT'], getmypid(), ...
http://php.net/manual/en/function.floor.php