SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    May 2006
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Your favorite mt_rand or array_rand

    Hi, if you could use only one forever for arrays, would you choose to use mt_rand or array_rand.. I know it depends on what you're doing, but if you could use for arrays for the best random item, and couldn't use the other, which one would you choose? Even if it means you might have to use a little more code, which one would you use. Please let me know I can't decide which one I'd rather use for a fix on something. I'm thinking mt_rand, since I've heard it's supposed to be better for arrays than the other, but I'm not positive if that is true after reading about them. Why I am asking you that have used them a lot, which one you would choose if could only choose one forever, for a better random item. Thank you.

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Since neither of them exists in JavaScript, I can't really say.

    In PHP, I like to use shuffle(), which internally uses rand().

  3. #3
    SitePoint Addict
    Join Date
    May 2006
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Whoops thank you.

  4. #4
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,084
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    New thread started with this question in the PHP forum: http://www.sitepoint.com/forums/showthread.php?t=712729

    Thread closed.
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy


Bookmarks

Posting Permissions

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