Help me out in this one ^^


Math Functions II

Well this is the outcome i got :
and this is the error :
Oops, try again. The random output you printed from your name should be just one character.
This is my code :

    print rand(1,9)."<br>";
    $name = "badr";
    $len = strlen( $name ) - 1;
    $rand = rand( -1 , $len);
    print substr( $name , $rand , $rand );

Help me out to find the error :slight_smile:


What happens if your write,

    $rand = rand(0, $len - 1);


    print substr($name, $rand, 1);


Didnt work :frowning:
I don't know the problem, The compiler shows 1 number and 1 letter, Yet i still get the error..


I don't know what I was thinking, you already subtracted one from the length. What happens when you write,

$rand = rand(0, $len)

There are two segments in the provided setup:

    // Use rand() to print a random number to the screen
    print rand(1,10);

    // Use your knowledge of strlen(), substr(), and rand() to
    // print a random character from your name to the screen.
    print substr("Weegillis",rand(0,strlen("Weegillis")-1),1);

Yours pretty much matches this. codewise, but it may be necessary to keep the provided structure..