Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 2007
    Posts
    273

    Choose random people name from list

    Hi guys, currently i have this line, that have static value about people name
    PHP Code:
    define('NAME''john'); 
    i want it choosing 1 name from this list randomly :
    john
    mike
    jack
    please help what is the code looks like, will give like for answering
    Lets be stable diligent person

  2. #2
    If u r using PHP try rand() function...

    php.net/manual/en/function.rand.php

  3. #3
    Join Date
    Dec 2011
    Location
    Montreal
    Posts
    334
    Quote Originally Posted by basketmen View Post
    Hi guys, currently i have this line, that have static value about people name
    PHP Code:
    define('NAME''john'); 
    i want it choosing 1 name from this list randomly :
    john
    mike
    jack
    please help what is the code looks like, will give like for answering

    I will do it like this, but you can do it in many ways:

    PHP Code:


    <?php

    function rnumber()
    //will generate a random number from 0 to 2, to have more //numbers change 3 in 4, 5 etc
    {
      
    srand(time());
        for (
    $i=0$i 3$i++)
        {
          
    $random = (rand()%3);
          
    $s[] = $random;
        }
      return 
    $s[1];
    }
    $for rnumber();
    $names = array("john","mike","jack"); //our array with names
    echo $names[$for] . "\n"// pick up random position in array
    ?>

    Is this what you want?Maybe I didn't understand correctly.

    Regards
    ROWEBCA
    Server Services

  4. #4
    Join Date
    Jul 2007
    Posts
    273
    thank you for all that answering, thumbs given
    Lets be stable diligent person

  5. #5
    Join Date
    Mar 2003
    Posts
    446
    Another way:

    $a = array('john', 'mike', 'jack');
    $r = array_rand($a);
    echo $a[$r];

  6. #6
    Join Date
    Apr 2013
    Location
    California
    Posts
    150
    Another way...

    $a = array('john', 'mike', 'jack');
    echo $a[rand() % count($a)];

  7. #7
    Join Date
    Jul 2007
    Posts
    273
    Quote Originally Posted by xrampage16 View Post
    Another way...

    $a = array('john', 'mike', 'jack');
    echo $a[rand() % count($a)];
    thanks bro
    Lets be stable diligent person

  8. #8
    Another solution:

    Code:
    <script language="Javascript">
    function name() { } ; b = new name() ; n = 0
    b[n++]= "john"
    b[n++]= "mike"
    b[n++]= "nick"
    i=Math.floor(Math.random() * n) ;
    document.write( b[i] )
    </script>
    Web Hosting by Brontobytes

Similar Threads

  1. Random People Can't Access Website
    By Storyboard Solutions in forum Web Hosting
    Replies: 24
    Last Post: 01-30-2013, 11:26 AM
  2. Replies: 16
    Last Post: 07-25-2010, 07:58 PM
  3. List 5 random facts about yourself
    By The Dude in forum Web Hosting Lounge
    Replies: 60
    Last Post: 01-02-2007, 08:39 PM
  4. Do you have people on your blocked List??
    By ATST in forum Web Hosting Lounge
    Replies: 5
    Last Post: 04-08-2003, 10:44 PM

Posting Permissions

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