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

Coding a sequential number generator

Discussion in 'PHP & Perl' started by springer98, Jan 15, 2009.

  1. springer98

    springer98 Regular Member

    Joined:
    Dec 6, 2008
    Messages:
    211
    Likes Received:
    250
    Occupation:
    We doeneeeeed no stinkin' yob!
    Location:
    ZRF
    I'm still learning php and am familiar with randomly rotating things like images or aff. links. I also understand sequentially displaying the same types of things but I'm stuck on doing something sequential with a number generator and a time requirement. Can anyone help me out with this?

    I'm looking for a sequential number generator that will display a steadily growing set of numbers, that will allow me to set a random time (server time) to generate a new, larger number.

    I'd also like to be able to choose the starting number, rather than have it begin at zero upon installation, and have no upper limit on how large the number can grow until I kill it.

    The number format should allow for 2 spaces beyond a decimal point, as in dollars and cents, and allow the number to grow incrementally in either full dollars, cents or a combination of both.

    Any help will be greatly appreciated.
     
  2. springer98

    springer98 Regular Member

    Joined:
    Dec 6, 2008
    Messages:
    211
    Likes Received:
    250
    Occupation:
    We doeneeeeed no stinkin' yob!
    Location:
    ZRF
    No one? Is this even possible with php, or should I look to another language?
     
  3. WickednDivine

    WickednDivine Executive VIP Premium Member

    Joined:
    Jul 29, 2008
    Messages:
    468
    Likes Received:
    344
    I think people are probably having a hard time trying to figure out what you're trying to do.

    at least I am. :confused:
     
  4. davidson

    davidson Registered Member

    Joined:
    Jul 26, 2008
    Messages:
    58
    Likes Received:
    95
    Generating a sequential number is not difficult. Where you may have a problem is advancing the number with time. A php script doesn't automatically run in the background like some other programming languages. So you would have to base your time calculations on something that is running constantly such as the server clock. Every time the script loads, you can check the server to see if the appropriate period of time has run and advance your sequence.
     
  5. springer98

    springer98 Regular Member

    Joined:
    Dec 6, 2008
    Messages:
    211
    Likes Received:
    250
    Occupation:
    We doeneeeeed no stinkin' yob!
    Location:
    ZRF
    Oh, sorry. I agonized over this, trying to get my idea across. Guess I did a poor job, eh? :eek:

    Essentially, I want to make something like a tote board, that would display a steadily increasing dollar figure. It would grow by a small, random amount every few seconds or minutes. The time intervals would be random, just as the dollar amounts would be.

    $1223.78 now
    $1233.00 in two minutes
    $1239.59 thirty-five seconds later... etc.

    Plus, I don't want it to reset to the original amount for each new visitor. I want it to continue to grow for as long as it's running.

    Was that a little more clear?

    Thanks.
     
  6. springer98

    springer98 Regular Member

    Joined:
    Dec 6, 2008
    Messages:
    211
    Likes Received:
    250
    Occupation:
    We doeneeeeed no stinkin' yob!
    Location:
    ZRF
    And you could do something like this? If so, and you're interested, PM me with a cost. Thanks!
     
  7. zone69

    zone69 Junior Member

    Joined:
    Nov 24, 2008
    Messages:
    196
    Likes Received:
    1,290
    not sure what you are exactly trying to do but the time() function will always increase if you keep the correct server time. It returns the time in epoch format. Of course if you change server time and don't use ntp to keep the server time synced you will have issues.
     
    • Thanks Thanks x 1
  8. davidson

    davidson Registered Member

    Joined:
    Jul 26, 2008
    Messages:
    58
    Likes Received:
    95
    I know enough PHP to be dangerous, but I am not a coder and I don't freelance in this area. Sorry.

    Just trying to let you know that it might be possible and give you and idea about how I would approach it.
     
  9. davidson

    davidson Registered Member

    Joined:
    Jul 26, 2008
    Messages:
    58
    Likes Received:
    95
    You know what ... there are scripts that reduce a dollar amount over a specific time increment. You see these scripts in reverse auction firesales. For example, the price reduces by 1 penny every few seconds until someone buys the item. You could find one of these and adapt it to your needs, randomizing the time period and the starting amount.

    just a though.
     
    • Thanks Thanks x 1
  10. springer98

    springer98 Regular Member

    Joined:
    Dec 6, 2008
    Messages:
    211
    Likes Received:
    250
    Occupation:
    We doeneeeeed no stinkin' yob!
    Location:
    ZRF
    Thanks, good idea! I'll look into that.

    I know what you mean about being dangerous with php, me too! :yield:

    Could be what I need is something entirely different from php. Maybe JS or one of the C languages or something.

    Thanks again.
     
  11. cooooookies

    cooooookies Senior Member

    Joined:
    Oct 6, 2008
    Messages:
    1,008
    Likes Received:
    216
    other languages offer to get the system time in miliseconds with 1970-1-1 as starting date, I would assume php also provides that, this is what you are looking for. Just code something like $money=$systemtime/10000 + {INITIALMONEY}
     
  12. zone69

    zone69 Junior Member

    Joined:
    Nov 24, 2008
    Messages:
    196
    Likes Received:
    1,290
    I don't have time at the moment to write you a db driven solution but here is very simple example without a db of something you could do. Hopefully it will give you some ideas.


    Code:
    <?php
    // this is your begin time which you can get using the time() function
    // I chose one quickly at the time I ran this
    $startTime=1232133897;
    
    // you could have this come from db instead of setting here
    $startAmount=25.00;
    
    // determine # of seconds from startTime till now
    $timeDiff=time()-$startTime;
    
    // this will add 1 penny per second but it can be adjusted easily
    $theAmount=$startAmount+($timeDiff/100);
    
    // amount will be 25.00 + number of seconds since $startTime
    // you could write this to the db and set $startAmount by fetching it next time
    echo $theAmount;
    
    ?>
    
    Hope that helps you out.
     
    • Thanks Thanks x 1
  13. springer98

    springer98 Regular Member

    Joined:
    Dec 6, 2008
    Messages:
    211
    Likes Received:
    250
    Occupation:
    We doeneeeeed no stinkin' yob!
    Location:
    ZRF
    That's an excellent start zone, thanks loads! I'm going to play around and see how much damage I can cause. :rolleyes:

    I really appreciate everyone's input.