Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to put in a wobble in a calculation
Message
From
17/10/2006 02:44:23
 
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01162413
Message ID:
01162419
Views:
25
This message has been marked as a message which has helped to the initial question of the thread.
>Hi all
>
>I have a few formulae that need to deviate from the values attained by a simple calculator, the deviation should be a wobble. Cause if it is a one sided deviation then the values over time will be totally out of whack, I want them back to around what the calcualtor would have other wise achieved but never tally with it.

I can think of a couple of ideas:

1. Suppose your calculator normally returns the value 10, and you'd like the result to "wobble" between, say, 9 and 11. In this example the target value (lnValue) is 10, and the total wobble "range" (lnRange) is 2. The RAND() function can help:
* Remember to seed the RAND() function exactly once in your program:
=RAND( -1 )

lnValue = 10
lnRange = 2
lnWobble = lnValue - ( lnRange / 2 ) + ( lnRange * RAND( ) )
In the example above, the resulting values will always be between 9 and 11 (cannot go outside that range) and the results will be evenly distributed over that range if you run enough trials.

2. Maybe you'd like the "wobble" to look more like a real-world statistical deviation. IOW, most of the time the values are close to your target value (i.e. 10); values farther away are possible, but more and more unlikely as you get farther from the target. One common function for this is the "normal" (Gaussian) distribution ( http://en.wikipedia.org/wiki/Normal_distribution ). Implementing this would give a very realistic looking "wobble" but there is no built-in function in VFP for this. You'd have to program it yourself.
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform