generating data problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Carramba

    generating data problem

    Hi!

    I am working on script that ll generate some random data, ll need it later
    on to fil db for testing.
    but know to my problem, I have limited generation of data to different
    char_sets depending on need, but
    the generated data is mixing all char_sets and I dont se why , so actually
    it's generates data on pwd condition, where all chat_set are allowed.
    hope you can help!

    <?php
    function generateSign ( $var , $length ){

    $charset_1 = "0123456789 ";
    $charset_2 = "abcdfghjkmnopq rstvwxyz";
    $charset_3 = "ABCDEFGHIJKLMN OPQRESTUVWXYZ";
    $possible =""; //<-- I allways reset it to null (?)

    if ( $var == 'num') {
    $possible = $charset_1;
    }

    if ( $var = 'text'){
    $possible = $charset_2;
    $possible .= $charset_3;
    }

    if ( $var = 'pwd' ){
    $possible = $charset_1;
    $possible .= $charset_2;
    $possible .= $charset_3;
    }

    if ( $var = null){
    die('Use: text , num, pwd. In function');
    }

    $i = 0;
    $password = "";
    while ( $i < $length ) {
    $sign = substr( $possible, rand( 0, strlen( $possible )-1 ), 1 );
    if ( !strstr( $generatedData, $sign ) ) {
    $generatedData .= $sign;
    $i++;
    }
    }
    return $generatedData;
    }

    $antal= 0;
    while( $antal < 10 ){
    $namn = strtolower( generateSign( 'text', '12' ) ); //<-- ll generate text
    sting including numbers
    $phone = generateSign('n um', '8' );//<-- ll generate text sting including
    char
    $email = strtolower( generateSign('t ext' , '6' ) ); //<-- ll generate text
    sting including numbers
    $pwd = md5( generateSign('p wd', '4') );
    echo $antal.' , '.$namn.' , '.$pwd.', '.$phone.' , '.$email.' <BR>';
    $antal++;
    }


    ?>

    --


    Thanx in advance
    _______________ _________



  • Carramba

    #2
    Re: generating data problem

    oh sorry for even possting it.. hehe
    didn't se misstyping.. = instead of ==
    all works fine..

    Comment

    • Chung Leong

      #3
      Re: generating data problem

      Also see http://fi.php.net/str_shuffle/.

      Comment

      • Steve

        #4
        Re: generating data problem

        In article <op.sz6eydu4eel 3e6@big>, nospam@note.com (Carramba) wrote:
        [color=blue]
        > *Subject:* Re: generating data problem
        > *From:* Carramba <nospam@note.co m>
        > *Date:* Sun, 13 Nov 2005 12:16:51 +0100
        >
        > oh sorry for even possting it.. hehe
        > didn't se misstyping.. = instead of ==
        > all works fine..
        >[/color]
        You're not the first, you certainly won't be the last...


        - Steve

        Comment

        Working...