tma/include/random.inc.php

43 lines
904 B
PHP
Raw Normal View History

2020-11-29 11:25:34 +01:00
<?php
2024-02-12 20:46:07 +01:00
2020-11-29 11:25:34 +01:00
// plante la graine...
2024-02-12 20:46:07 +01:00
@mt_srand((float) microtime() * 1000000);
2020-11-29 11:25:34 +01:00
function RandomColors()
{
2024-02-12 20:46:07 +01:00
$colors = array("ccccff","cceecc","ffcccc","eeccee","ffccff","cceeee","cceeff");
$color[0] = $color[1] = "000000";
2020-11-29 11:25:34 +01:00
2024-02-12 20:46:07 +01:00
while ($color[0] == $color[1]) {
$color[0] = $colors[mt_rand(0, count($colors) - 1)];
$color[1] = $colors[mt_rand(0, count($colors) - 1)];
}
2020-11-29 11:25:34 +01:00
2024-02-12 20:46:07 +01:00
@array_splice($colors, 0);
2020-11-29 11:25:34 +01:00
2024-02-12 20:46:07 +01:00
return $color;
2020-11-29 11:25:34 +01:00
}
function RandomFile($dirname)
{
2024-02-12 20:46:07 +01:00
$i = 0;
$d = opendir($dirname);
2020-11-29 11:25:34 +01:00
2024-02-12 20:46:07 +01:00
while (false !== ($rfile = readdir($d))) {
if (($rfile[0] != ".") && is_file($dirname."/".$rfile)) {
$listfiles[++$i] = $rfile;
}
}
closedir($d);
2020-11-29 11:25:34 +01:00
2024-02-12 20:46:07 +01:00
if (count($listfiles) > 1) {
$rfile = $listfiles[mt_rand(1, count($listfiles))];
} else {
$rfile = $listfiles[1];
}
2020-11-29 11:25:34 +01:00
2024-02-12 20:46:07 +01:00
@array_splice($listfiles, 0);
2020-11-29 11:25:34 +01:00
2024-02-12 20:46:07 +01:00
return $rfile;
2020-11-29 11:25:34 +01:00
}