Beispiel #1
0
/**
 * Create random value on give criteria
 *
 * @param int $length
 * @param string $type (mixed, chars, digits)
 * @return string
 */
function generateRandomString($length, $type = null)
{
    if ($length === null) {
        $length = 12;
    }
    if ($type === null) {
        $type = 'mixed';
    }
    if ($type != 'mixed' && $type != 'chars' && $type != 'digits') {
        return false;
    }
    $rand_value = '';
    while (strlen($rand_value) < $length) {
        if ($type == 'digits') {
            $char = myRand(0, 9);
        } else {
            $char = chr(myRand(0, 255));
        }
        if ($type == 'mixed') {
            if (preg_match('/^[a-z0-9]$/i', $char)) {
                $rand_value .= $char;
            }
        } elseif ($type == 'chars') {
            if (preg_match('/^[a-z]$/i', $char)) {
                $rand_value .= $char;
            }
        } elseif ($type == 'digits') {
            if (preg_match('^[0-9]$', $char)) {
                $rand_value .= $char;
            }
        }
    }
    return $rand_value;
}
Beispiel #2
0
function a_star_test()
{
    $map = myArrayFill(0, NODE_HEIGHT, myStrRepeat('A', NODE_WIDTH));
    generate(node(myRand(1, (NODE_WIDTH + NODE_WIDTH % 2) / 2 - 1) * 2 - 1, myRand(1, (NODE_HEIGHT + NODE_HEIGHT % 2) / 2 - 1) * 2 - 1), $map);
    $start = node(1, 1);
    $target = node(NODE_WIDTH + NODE_WIDTH % 2 - 3, NODE_HEIGHT + NODE_HEIGHT % 2 - 3);
    $path = a_star($start, $target, $map);
    myArrayUnshift($path, $start);
    foreach ($path as $i) {
        $arr = coord($i);
        $map[$arr[0]][$arr[1]] = '*';
    }
    return null;
}