当前位置: 首页>>代码示例>>PHP>>正文


PHP gen_random函数代码示例

本文整理汇总了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);
}
开发者ID:jemmy655,项目名称:hippyvm,代码行数:8,代码来源:heapsort.php

示例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]);
}
开发者ID:michaelprem,项目名称:phc,代码行数:13,代码来源:bench_heapsort.php

示例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);
    }
}
开发者ID:bennett000,项目名称:benchmarksgame,代码行数:39,代码来源:fasta.php

示例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));
开发者ID:michaelprem,项目名称:phc,代码行数:21,代码来源:random.php

示例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]);
开发者ID:michaelprem,项目名称:phc,代码行数:31,代码来源:heapsort.php

示例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";
}
开发者ID:michaelprem,项目名称:phc,代码行数:16,代码来源:nested_statements.php

示例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";
    }
}
开发者ID:Byron,项目名称:benchmarksgame-cvs-mirror,代码行数:30,代码来源:fastaredux.php-4.php


注:本文中的gen_random函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。