Assume a typical (I think) PRNG $\mathop{\mathrm{rand}}(n) = \omega$ where $\{\; \omega \in \mathbb{R} \mid 0 < \omega \le n \;\}$ for $n > 0$.
I want to create a random function $f(x)$, such that $f(x) = y$ is a real number within $\pm 9.9\bar{9} \times 10^{\pm x}$ and, crucially, $\lfloor \log _{10} f(x) \rfloor$ is a random integer within $\pm x$.
Perhaps more accurately,[2] if we write $f(x) = y$ as $f(x) = a \times 10^b$,[1] then $\{-x \le b \le x \}$, and all $b$ within that range are equally likely, for a given $x$.
The results needn't stand up to rigorous statistical scrutiny. Since I don't know what kind of answers (if any!) this question will get, hopefully it's enough to say, "the fairer the distribution, the better".
My best attempt
The following seems to produce reasonable results, although I hope this can be improved to something more concise, ideally with only one $\mathop{\mathrm{rand}}(n)$.
$f(x) = (\mathop{\mathrm{rand}}(20)-10)\times 10^{\mathop{\mathrm{rand}}(2x)-x}$
Non-decimal radix
Although my question is specific to base-10, general solutions for any arbitrary radix would be welcome as well.
- Normal scientific notation, i.e., $\{ -10 < a < 10 \}$
- My math is quite rusty. I will accept any edits to improve the language/notation in my question.