Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: random

  1. #1
    New Coder
    Join Date
    Aug 2002
    Location
    Toronto, Canada
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts

    random

    Hello,

    can someone sugest me a way to create a random sequence of letters and numbers ? I have a script that does that .. but it's very incosistent. What's happening is ... one time it will create a 20 caracter string, but next time it will only create a 5 caracter string. here it is below.

    PHP Code:

    $length 
    =  20;// set this to legth of the random word/number
    $p "0wxVWvKH678FSbkUXIJ".
    "aefglm9ijD5yGupqrs"
    "AE3cdLMNOPhtz124BYCZQRnoT";
    $r1 substr($p, (rand() % strlen($p)), $length);
    $string $r1
    any sugestions ?

    HormonX

  • #2
    New Coder
    Join Date
    Jul 2002
    Location
    Behind my PC :)
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm currently using this for random pieces of text and letters.
    works great for me...

    PHP Code:
    function GeneratePWD($length){
        
    $letters = array(
        
    'a','b','c','d','e','f','g','h',
        
    'i','j','k','l','m','n','o','p',
        
    'q','r','s','t','u','v','w','x',
        
    'y','z',
        
    'A','B','C','D','E','F','G','H',
        
    'I','J','K','L','M','N','O','P',
        
    'Q','R','S','T','U','V','W','X',
        
    'Y','Z',
        
    '0','1','2','3','4','5','6','7',
        
    '8','9');
        
    srand((double) microtime() * 1000000);
        for (
    $c 0$c $length$c++)
            
    $password .= $letters[rand(0,count($letters))];
        return 
    $password

    Last edited by Robbie; 10-28-2002 at 09:20 PM.

  • #3
    New Coder
    Join Date
    Aug 2002
    Location
    Toronto, Canada
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanx robbie for that tip.

    HormonX

  • #4
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    PHP Code:
    srand((double)microtime()*1000000);
    $ID substr(md5(rand(0,32000)), 010);
    $r rand(0,1);
    if (
    $r == "0") {
        
    $ID;
    } else {
        
    $ID strtoupper($ID);
    }

    $password $ID


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •