String of 5 unique random letters

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • miraan
    New Member
    • Apr 2008
    • 24

    String of 5 unique random letters

    Hi,
    Right now I am working on creating a string of 5 random letters. I have already created the script, it does create a unique random letter but it repeats it 5 times. Here is what I have so far:

    Code:
    <?php
    srand();
    $random=chr(rand(ord("A"),ord("Z")));
    $string="";
    for ($i=1;$i<6;$i++) {
    	$string .= $random;
    }
    echo $string;
    ?>
    It diplays 5 of the same letters, I want unique letters.
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    By calling it as a function produces a unique letter:
    Code:
    srand();
    function randletter()
    {
    	return  chr(rand(ord("A"),ord("Z")));
    }
    $string="";
    for ($i=1;$i<6;$i++) {
    	$string .= randletter();
    }
    echo $string;

    Comment

    • miraan
      New Member
      • Apr 2008
      • 24

      #3
      Thanks alot, it worked!

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Originally posted by miraan
        Thanks alot, it worked!
        Great!


        Regards.

        Comment

        Working...