Example #1
0
function fractionrand($d)
{
    $goodnum = array('4' => array(1, 3), '6' => array(1, 5), '8' => array(1, 3, 5, 7), '10' => array(1, 3, 7, 9), '12' => array(1, 5, 7, 11));
    $d = round($d);
    if ($d < 1) {
        echo "denominator must be larger than 1";
        return "";
    }
    if (isset($goodnum[$d])) {
        $n = randfrom($goodnum[$d]);
    } else {
        do {
            $n = rand(1, $d - 1);
        } while (gcd($d, $n) != 1);
    }
    return "{$n}/{$d}";
}
Example #2
0
function chem_randanion($group = "all", $type = "common", $uncommon = false)
{
    global $chem_anions;
    if ($group == "polyatomic") {
        $pickfrom = range(10, 36);
    } else {
        $pickfrom = range(0, 8);
    }
    if ($uncommon && $group != 'polyatomic') {
        $pickfrom[] = 9;
    }
    if ($group == "all") {
        $pickfrom = array_merge($pickfrom, range(10, 36));
    }
    if ($uncommon && ($group == "all" || $group == "polyatomic")) {
        $pickfrom[] = 35;
    }
    $r = randfrom($pickfrom);
    $name = $type == "alternate" && $chem_anions[$r][3] != '' ? $chem_anions[$r][3] : $chem_anions[$r][2];
    return array($chem_anions[$r][0], $chem_anions[$r][1], $name);
}