예제 #1
0
function fractiondiffdrands($min, $max, $n)
{
    $ds = diffrands($min, $max, $n);
    $out = array();
    foreach ($ds as $d) {
        $out[] = fractionrand($d);
    }
    return $out;
}
예제 #2
0
function getprimes($n, $digits = 0)
{
    global $primes;
    $out = array();
    if ($digits == 0) {
        $c1 = count($primes[1]);
        $c2 = count($primes[2]);
        $c3 = count($primes[3]);
        $c4 = count($primes[4]);
        $c5 = count($primes[5]);
        $c6 = count($primes[6]);
        $locs = diffrands(0, $c1 + $c2 + $c3 + $c4 + $c5 + $c6 - 1, $n);
    } else {
        if ($digits < 0 || $digits > 6) {
            echo "{$digits} digit primes not supported.";
            return array();
        } else {
            $locs = diffrands(0, count($primes[$digits]) - 1, $n);
        }
    }
    foreach ($locs as $r) {
        if ($digits == 0) {
            if ($r < $c1) {
                $out[] = $primes[1][$r];
            } else {
                if ($r < $c1 + $c2) {
                    $out[] = $primes[2][$r - $c1];
                } else {
                    if ($r < $c1 + $c2 + $c3) {
                        $out[] = $primes[3][$r - $c1 - $c2];
                    } else {
                        if ($r < $c1 + $c2 + $c3 + $c4) {
                            $out[] = $primes[4][$r - $c1 - $c2 - $c3];
                        } else {
                            if ($r < $c1 + $c2 + $c3 + $c4 + $c5) {
                                $out[] = $primes[5][$r - $c1 - $c2 - $c3 - $c4];
                            } else {
                                $out[] = $primes[6][$r - $c1 - $c2 - $c3 - $c4 - $c5];
                            }
                        }
                    }
                }
            }
        } else {
            $out[] = $primes[$digits][$r];
        }
    }
    return $out;
}
예제 #3
0
function graphschedulemultchoice($g, $t, $L, $p)
{
    $sc = graphlistprocessing($g, $t, $L, $p);
    $tocomp = serialize($sc);
    $n = count($L) - 1;
    $out = array($sc);
    $found = 0;
    for ($cnt = 0; $cnt < 20 && $found < 4; $cnt++) {
        $pl = diffrands(0, $n - 1, $n);
        $pl[] = $n;
        $newsc = graphlistprocessing($g, $t, $pl, $p);
        if (serialize($newsc) != $tocomp) {
            $found++;
            $out[] = $newsc;
        }
    }
    //echo "its: $cnt, found: $found<br/>";
    return $out;
}
예제 #4
0
function matrixrandunreduce($m, $c)
{
    $n = count($m);
    for ($i = 0; $i < $c; $i++) {
        $r = diffrands(0, $n - 1, 3);
        $m = matrixrowcombine3($m, $r[0], -1, $r[1], 1, $r[2], 2, $r[0]);
    }
    for ($i = 0; $i < $c; $i++) {
        list($sr, $er) = diffrands(0, $n - 1, 2);
        $m = matrixrowswap($m, $sr, $er);
    }
    $c = 0;
    while (hasallzerorow($m) && $c < 20) {
        $r = diffrands(0, $n - 1, 3);
        $m = matrixrowcombine3($m, $r[0], -2, $r[1], 1, $r[2], 3, $r[0]);
        $c++;
    }
    return $m;
}
예제 #5
0
function chem_getdiffrandcompounds($c, $type = "twobasic,twosub,threeplus,parens")
{
    global $chem_compounds;
    $types = explode(',', $type);
    $n = array();
    foreach ($types as $v) {
        $n[] = count($chem_compounds[$v]);
    }
    $r = diffrands(0, array_sum($n) - 1, $c);
    $out = array();
    foreach ($types as $i => $v) {
        foreach ($r as $k => $rv) {
            if ($rv < $n[$i]) {
                $out[] = $chem_compounds[$v][$rv];
                unset($r[$k]);
            } else {
                $r[$k] -= $n[$i];
            }
        }
    }
    return $out;
}
예제 #6
0
function randnames($n = 1, $gender = 2)
{
    global $namearray;
    if ($n == 1) {
        if ($gender == 2) {
            $gender = rand(0, 1);
        }
        return $namearray[$gender][rand(0, 137)];
    } else {
        $out = array();
        $locs = diffrands(0, 137, $n);
        for ($i = 0; $i < $n; $i++) {
            if ($gender == 2) {
                $gender = rand(0, 1);
            }
            $out[] = $namearray[$gender][$locs[$i]];
        }
        return $out;
    }
}