Pseudo-random month based selection

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • megahurtz
    New Member
    • Sep 2007
    • 7

    #1

    Pseudo-random month based selection

    This isn't necessarily specific to PHP, but I am trying to figure out a way to pseudo-randomly generate a number based on the month. To clarify a little, I want the number returned to stay the same for the entire month, and then change to another "random" number for the next month. There would also need to be a ceiling on how big the number could be. I can't think of a way to write this, is there anyone able to help?
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    You can use the mt_rand function to generate a random number. You can even specify the lowest and highest limits.

    As to using a single random number for the entire month. You will obviously have to store this number somewhere, where it can be read by your code. I would probably use a Database, like MySQL.
    You would simply have to have a field for your random number, and a date field for the month it represents. If there is not a field for the current month, you use the function to generate a new number and add it for the current month.

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      Heya, megahurtz.

      [code=php]
      srand(date('m') );
      [/code]

      Comment

      Working...