I've been run into a problem which is absolutely not as simple as is looking, I just don't know how to describe it.I think it is a math problem eventually?
Suppose a target number A and a mistake C given, and require a random number x, then we have
$$ \left |\frac{x-A}{A} \right |<\pm C $$ and then generate a x between this: $$ (1-C)A<x<(1+C)A $$ then I generate the next x BASED ON THE LAST NUMBER, which means $$ \left |\frac{x-A}{A} \right |<\pm C , A=x_{1} $$
OK, here comes the hardest part: The average of those x must be in the mistake given with the first A, that is $$ \frac{\frac{1}{n}\sum\limits_{i=1}^nx_i - A}{A}<C $$
I don't know if I make it clear my brain is soooooo MESSEDUP now.I think you guys can get the idea right??any pointer will be grateful!!!
here is a simple C program simplely implements the first part
the problem is how to control the generate rules so that the final mistake is in control.
Too long for a comment, so assuming I deciphered the question right, you seem to want to generate $n$ "random" numbers $x_i, 1 \le i \le n$, with $x_0=A$ and $\left|\dfrac{x_{i}-x_{i-1}}{x_{i-1}} \right| < C$, s.t. $\left|\dfrac{\sum x_{i}-nA}{nA} \right| < C$. So you need $$x_{i-1}(1-C) < x_i < x_{i-1}(1+C) \quad \forall i \in {1, 2, ...n} \tag{1}$$ and $$nA(1-C) < \sum x_i < nA(1+C) \tag{2}$$
Assuming further that by random you mean uniformly distributed, $(1)$ can be implemented easily, recursively. If $n$ is small, a simple solution would be to generate $n \; x_i$ satisfying $(1)$ and then reject the whole lot if $(2)$ fails.