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 5 of 5

Thread: random numbers

  1. #1
    New Coder
    Join Date
    Jun 2005
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    random numbers

    hi, i would like to make a script that generates a thousand random number between 0 and 37 inclusive

    then 0 and 37 are highlighted red

    all other odd and evn numbers are either blue or green


    is this possible please?

  • #2
    Senior Coder gsnedders's Avatar
    Join Date
    Jan 2004
    Posts
    2,340
    Thanks
    1
    Thanked 7 Times in 7 Posts
    PHP Code:
    <?php

    $num 
    mt_rand(0,37);

    if (
    $num == || $num == 37)
    {
    echo 
    "<span style=\"color: #f00;\">$num</span>";
    }
    elseif (
    $num 2)
    {
    echo 
    "<span style=\"color: #0f0;\">$num</span>";
    }
    else
    {
    echo 
    "<span style=\"color: #00f;\">$num</span>";
    }

    ?>
    I *think* this is what you mean, as your request isn't completely clear.

  • #3
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    He also wanted a thousand numbers.
    PHP Code:
    for($i 0$i 1000$i++)
    {
       
    $num mt_rand(037);
       print 
    $num;
       if(
    $num 2)
       {
           print 
    ' odd';
       }
       else
       {
           print 
    ' even';
       }
       print 
    "\n";

    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #4
    Senior Coder gsnedders's Avatar
    Join Date
    Jan 2004
    Posts
    2,340
    Thanks
    1
    Thanked 7 Times in 7 Posts
    But he also wanted the colouring, so it'd be:
    PHP Code:
    <?php 

    for ($i 0$i 1000$i++)
    {
        
    $num mt_rand(0,37); 
        
        if (
    $num == || $num == 37
        { 
            echo 
    "<span style=\"color: #f00;\">$num</span>"
        } 
        elseif (
    $num 2
        { 
            echo 
    "<span style=\"color: #0f0;\">$num</span>"
        } 
        else 
        { 
            echo 
    "<span style=\"color: #00f;\">$num</span>"
        } 
        echo 
    '<br />';
    }

    ?>

  • #5
    New Coder
    Join Date
    Jun 2005
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts
    omg than you all

    it works


  •  

    Posting Permissions

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