# guess a number proportional to another [closed]

This is a challenging question. I am not sure how to begin coding it, or whether it is easily possible in TeX.

I wish to define a command that takes in input of a simple formula such as Z = X x N + N^2. There is always a single number Z followed by an equality, do \def can be used to parse it. X too is a number in the same order of magnitude as Z, or one order of magnitude larger, at most.

The command guesses a random number N proportional to Z. (In the same order of magnitude?)

1) If Z + 0.4 > X x N + N^2, then store N as \useguessN.

2) If Z + 0.4 not > X x N + N^2, then subtract 0.8, lets say, from N, store that as the new N, and try 1) again.

It's fine (in fact desirable) that the result is only approximate. This is for randomly generating certain curves in tikz which are geometrically constrained by the same formula but still randomly different. For automatically making diagrams that appear hand-drawn.

QUESTION: Can this be done without lagging document compilation?

If yes, how?

The basic structure of the document aimed at is this:

\documentclass{standalone}\usepackage{tikz}

[define the guesser]

[run guesser with parameters] result is a number \useguessN.

\begin{document}\begin{tikzpicture}

[input \useguessN into an tikz diagram as a numerical parameter in another macro I have defined]

\end{tikzpicture}\end{document}


EDIT: Yes, I can use existing algorithms implemented in Mathematica, for instance, and input the answers manually, but the goal is to automate the procedure to get certain types of random numbers for diagramming strokes as needed.

## closed as unclear what you're asking by user31729, egreg, moewe, Mico, Paul GaboritApr 6 '15 at 10:55

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• The question is not very clear. Depending on the values the "approximation algorithm" might end up in an infinite loop. Also the first form uses variables Z, Y, and X, but the algorithm uses N. From the description, the form is not required to contain N, the form has only to start with Z=. Try Newton's method or other approximation methods for complicate forms. In case Z = YX + X^2, the form is linear in Z or Y and quadratic in X, thus it's a piece of cake to calculate X, Y, or Z, if the other two variables are given. – Heiko Oberdiek Mar 29 '15 at 18:56
• please tell us if you want to use that formula only or others too. (and what is X ?) – user4686 Mar 29 '15 at 19:16
• What's the distribution of the "random number N" supposed to be: discrete or continuous? If continuous: normal (with which mean and variance?), uniform (over which interval?), etc? – Mico Mar 31 '15 at 21:00