本文整理汇总了PHP中gen_random函数的典型用法代码示例。如果您正苦于以下问题:PHP gen_random函数的具体用法?PHP gen_random怎么用?PHP gen_random使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了gen_random函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: heapsort
function heapsort($N)
{
$ary = array(0);
for ($i = 1; $i <= $N; $i++) {
$ary[$i] = gen_random(1);
}
heapsort_r($N, $ary);
}
示例2: heapsort
function heapsort($N)
{
global $LAST;
define("IM", 139968);
define("IA", 3877);
define("IC", 29573);
$LAST = 42;
for ($i = 1; $i <= $N; $i++) {
$ary[$i] = gen_random(1);
}
heapsort_r($N, $ary);
printf("%.10f\n", $ary[$N]);
}
示例3: makeRandomFasta
function makeRandomFasta(&$genelist, $n)
{
$width = 60;
$lines = (int) ($n / $width);
$pick = str_repeat('?', $width) . "\n";
$randoms = array_fill(0, $width, 0.0);
global $last;
// full lines
for ($i = 0; $i < $lines; ++$i) {
gen_random($last, $randoms);
$j = 0;
foreach ($randoms as $r) {
foreach ($genelist as $k => $v) {
if ($r < $v) {
break;
}
}
$pick[$j++] = $k;
}
echo $pick;
}
// last, partial line
$w = $n % $width;
if ($w !== 0) {
$randoms = array_fill(0, $w, 0.0);
gen_random($last, $randoms);
$j = 0;
foreach ($randoms as $r) {
foreach ($genelist as $k => $v) {
if ($r < $v) {
break;
}
}
$pick[$j++] = $k;
}
$pick[$w] = "\n";
echo substr($pick, 0, $w + 1);
}
}
示例4: define
<?php
/*
$Id: random.php,v 1.2 2004/04/21 14:23:45 tim Exp $
http://www.bagley.org/~doug/shootout/
tweaked by tim
*/
define("IM", 139968);
define("IA", 3877);
define("IC", 29573);
$LAST = 42;
function gen_random($max)
{
global $LAST;
return $max * ($LAST = ($LAST * IA + IC) % IM) / IM;
}
$N = 1000000;
while ($N--) {
gen_random(100.0);
}
printf("%.9f\n", gen_random(100.0));
示例5: while
$ra[1] = $rra;
return;
}
}
$i = $l;
$j = $l << 1;
while ($j <= $ir) {
if ($j < $ir && $ra[$j] < $ra[$j + 1]) {
$j++;
}
if ($rra < $ra[$j]) {
$ra[$i] = $ra[$j];
$j += $i = $j;
} else {
$j = $ir + 1;
}
}
$ra[$i] = $rra;
}
}
$N = $argc == 2 ? $argv[1] : 10000;
for ($i = 1; $i <= $N; $i++) {
$ary[$i] = gen_random(1);
}
/*
for ($i=0; $i<$N; $i++) {
printf("%4d %.15f\n", $i, $ary[$i]);
}
*/
heapsort($N, $ary);
printf("%.10f\n", $ary[$N]);
示例6: define
<?php
// Taken from the Zend benchmark. Shredding should take care of the compound assignment
define("IM", 139968);
define("IA", 3877);
define("IC", 29573);
$LAST = 42;
function gen_random($n)
{
global $LAST;
return $n * ($LAST = ($LAST * IA + IC) % IM) / IM;
}
for ($i = 0; $i < 20; $i++) {
$x = gen_random($i);
echo "{$x}\n";
}
示例7: makeRandomFasta3
function makeRandomFasta3(&$genelist, $n)
{
$width = 60;
$lines = (int) ($n / $width);
$pick = "";
$randoms = array_fill(0, $width, 0.0);
global $last;
// full lines
for ($i = 0; $i < $lines; ++$i) {
$pick = "";
gen_random($last, $randoms);
$j = 0;
foreach ($randoms as $r) {
$pick .= $genelist[(int) ($r * 100)];
}
echo $pick . "\n";
}
// last, partial line
$w = $n % $width;
if ($w !== 0) {
$pick = "";
$randoms = array_fill(0, $w, 0.0);
gen_random($last, $randoms);
$j = 0;
foreach ($randoms as $r) {
$pick .= $genelist[(int) ($r * 100)];
}
echo $pick . "\n";
}
}