1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

random events

Discussion in 'Code Snippets and Tutorials' started by Wings, Oct 28, 2011.

  1. Wings

    Wings Level III

    Joined:
    Jun 21, 2009
    Messages:
    573
    Likes Received:
    6
    Location:
    Montreal, Québec
    Hey all! I was wondering how do you implement random events in a website like neopets? I guess it's a code that uses probabilities but what does it look like?
     
  2. Lightning

    Lightning Administrator
    Staff Member

    Joined:
    Nov 8, 2008
    Messages:
    3,021
    Likes Received:
    195
    Gender:
    Male
    Location:
    Florida, USA
    There are many ways to, but a simple way to do it is to use PHP.

    There is a random function called mt_rand(). http://php.net/manual/en/function.mt-rand.php
    If you don't want a person to have too many random events, you could have an entry in an SQL data table for each user for the last time that they got an event like that. If the last time is long enough in the past, then if mt_rand(1, 100000000) = 5820, then generate an event.
     
  3. Wings

    Wings Level III

    Joined:
    Jun 21, 2009
    Messages:
    573
    Likes Received:
    6
    Location:
    Montreal, Québec
    Thank you very much Lightning :)