Coding a sequential number generator

springer98

Regular Member
Joined
Dec 6, 2008
Messages
211
Reaction score
251
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.
 
No one? Is this even possible with php, or should I look to another language?
 
No one? Is this even possible with php, or should I look to another language?

I think people are probably having a hard time trying to figure out what you're trying to do.

at least I am. :confused:
 
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.
 
I think people are probably having a hard time trying to figure out what you're trying to do.

at least I am. :confused:

Oh, sorry. I agonized over this, trying to get my idea across. Guess I did a poor job, eh? :o

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.
 
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.

And you could do something like this? If so, and you're interested, PM me with a cost. Thanks!
 
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.
 
And you could do something like this? If so, and you're interested, PM me with a cost. Thanks!

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.
 
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.
 
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, 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.
 
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}
 
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.
 
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.

Hope that helps you out.

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.
 
Back
Top