Need a php help - random Generating

Discussion in 'PHP' started by PowerExtreme, Mar 20, 2008.

  1. #1
    i want to modify a script a little

    rite now its generating random entries

    Using this code

    gencode(rand(3,10))
    Code (markup):

    I Want it give values numerical wise (eg 1-2-3-4-5 and so on)

    what should i doo

    Thanks
     
    PowerExtreme, Mar 20, 2008 IP
  2. ezprint2008

    ezprint2008 Well-Known Member

    Messages:
    611
    Likes Received:
    15
    Best Answers:
    2
    Trophy Points:
    140
    Digital Goods:
    1
    #2
    check the PHP manual www.php.net

    Thats a simple question that is covered in basics
     
    ezprint2008, Mar 20, 2008 IP
  3. PowerExtreme

    PowerExtreme Banned

    Messages:
    2,118
    Likes Received:
    75
    Best Answers:
    0
    Trophy Points:
    0
    #3
    aah can some one help here itself

    i tried i++ but doesnt work properly that way
     
    PowerExtreme, Mar 20, 2008 IP
  4. LimeBlast

    LimeBlast Peon

    Messages:
    81
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Mabe take a look at this script ... http://phpbuddy.com/article.php?id=25
     
    LimeBlast, Mar 23, 2008 IP
  5. NavyChief

    NavyChief Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Something similar to this?

    
    <?php
     
     
    $valid = false;
     
    while( !$valid )
    {
              $num1 = rand(1,9);
              $num2 = rand(1,9);
              $num3 = rand(1,9);
              $num4 = rand(1,9);
              $num5 = rand(1,9);
              $num6 = rand(1,9);
              $num7 = rand(1,9);
              $num8 = rand(1,9);
              $num9 = rand(1,9);
              
              $calc = ( $num1 * 1 ) + ( $num2 * 2) + ( $num3 * 3) + ( $num4 * 4) + ( $num5 * 5) + ( $num6 * 6) + ( $num7 * 7) + ( $num8 * 8) + ( $num9 * 9);
              
              $numb = $calc / 11;
              
              if( is_int( $numb ) )
              {
                        echo $num9 . $num8 . $num7 . $num6 . $num5 . $num4 . $num3 . $num2 . $num1;
                        $valid = true;
              }
    }
     
    ?>
    
    Code (markup):
     
    NavyChief, Mar 24, 2008 IP
  6. starlord

    starlord Guest

    Messages:
    435
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #6


    That was helpful !


    but I think NavyChief has the answer there for you mate ...

    Starlord
     
    starlord, Mar 25, 2008 IP
  7. lawrenz

    lawrenz Peon

    Messages:
    246
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    try using for loop hehehe

    for($i=1;$i<=10;$i++)
    {
    echo "$i <br>";
    }

    hehehe
     
    lawrenz, Mar 25, 2008 IP
  8. lephron

    lephron Active Member

    Messages:
    204
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #8
    
    $max = 9; // number you want to count to
    for($i = 0; $i < $max; $i++)
    {
        gencode($i);
    }
    
    PHP:
     
    lephron, Mar 25, 2008 IP
  9. PowerExtreme

    PowerExtreme Banned

    Messages:
    2,118
    Likes Received:
    75
    Best Answers:
    0
    Trophy Points:
    0
    #9
    i dont want a random number i want it in sequel

    like first comes 1 then 2 thn 3 n 4 etc etc
     
    PowerExtreme, Mar 26, 2008 IP
  10. unknowngiver

    unknowngiver Peon

    Messages:
    94
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    powerextreme lawrenz already answered that questionand so did lephron

    if you jsut want it to echo the number in sequence [and not go into the function gencode] then look at lawrenz post..if you want it in sequence but then that number goes in the function gencode then read lephron's reply
    all you need to do is run a forloop :) like the above 2 users showed
     
    unknowngiver, Mar 26, 2008 IP