[QUIZ] Fuzzy Time (#99)

P

Paolo Negri

Method 3
I choose my offset through a dedicated class (WanderingWalker) that
works always in seconds.
Basicly I start from the current offset (or position) and I genereta a
target to reach (by default a random number between -300 + 300) after
that I begin moving my offset of 1 unit per every consumed second in
the direction of the target. So in one second my offset moves of +/- 1
second, in one minute moves of +/- 60 seconds and so on.
When I reach the given target offset I just generate another target to reach.
I choosed this approach because it forces the clock to reach smoothly
any generated target at any update rate, and, in theory, moving the
offset this way is possible to avoid the check against going back with
the time.
But since I'm lazy I didn't tested/verified my theory so I had to keep
this check in my code.

cheers

Paolo
 
T

Tom Pollard

I choose my offset through a dedicated class (WanderingWalker) that
works always in seconds.
Basicly I start from the current offset (or position) and I genereta a
target to reach (by default a random number between -300 + 300) after
that I begin moving my offset of 1 unit per every consumed second in
the direction of the target. So in one second my offset moves of +/- 1
second, in one minute moves of +/- 60 seconds and so on.
When I reach the given target offset I just generate another target
to reach.
I choosed this approach because it forces the clock to reach smoothly
any generated target at any update rate, and, in theory, moving the
offset this way is possible to avoid the check against going back with
the time.

That's interesting. The insight I had, after trying my first two
methods, was that to get the distribution to be balanced, the
distribution for each random change had to be balanced as well.
However, since you can't reduce the offset arbitrarily without
worrying that the clock will regress, you need to restrict positive
changes in the offset to be no greater than the greatest negative
offset you can choose. Because your method adjusts the offset
gradually to reach a randomly chosen target, you can choose the
target freely from [-5..5] (minutes), whereas I'm restricted to
[-1..1]. You end up with Gaussian-like distribution, rather than a
flat distribution, because the steps you take between targets end up
being part of the distribution as well.

Unlike yours, my method (as currently implemented) only works as
intended when the time is updated once a minute. I should really be
adjusting the range over which the offset is selected based on the
step size. Your method works equally well regardless of the step size.

Tom
 
T

Tom Pollard

On Oct 31, 2006, at 1:05 AM, Tom Pollard wrote:
Out of curiosity, I tried translating Cameron's method into my code.
[...]
Cameron's method
* Choose offset uniformly from the set [-5..1], , but don't change
the reported time if the chosen offset would cause it to retrogress.
-5 -4 -3 -2 -1 0 1 2 3 4 5
0.0 1.2 7.2 18.1 28.4 28.3 16.7 0.0 0.0 0.0 0.0

That part of my code is kind of obsfuscated, but what it actually does
is choose an offset uniformly from the set [-20..5], but don't change
the reported time if the chosen offset would cause it to retrogress.
This would be roughly equivalent to saying: do not choose a new offset
60% of the time. Otherwise, choose from the set [-5..+5] but don't
retrogress below the low-water-mark.

Yes, I see that now. (Thanks for the correction.) I think it's an
elegant way to deal with the problem, and one that I would probably
never have thought of, myself.

Cheers,

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,073
Messages
2,570,538
Members
47,195
Latest member
RedaMahuri

Latest Threads

Top