I have task I can't get my head around, even with a suggested answer.
You have a function the generates a random integer between $0 - 65535$. Your task is to generate random integers $125-525$ with this function, these numbers must be generated with equal prevalence.
A friend said his solution was $\frac{x}{65536} * 401 + 125$ but I don't understand how he got there nor the answer in general.
EDIT: NB: If you have a solution for the number 65535, please provide, what we have here is a reformulation of the question to 65363 integers (65362 for even 401 divide).
$a_1 = 0$
$b_1 = 65362$
$X = b_1-a_1$
$Y=\frac{X}{163}+125$
if x = 65362 the output is 525
if x = 0 the output is 125
This looks like a solution to me.
I will expand on my comment.
If we simply try scaling the random number from $0$-$65535$ into the range $125$-$525$, then the resulting distribution will not be uniform. For example, $\left\lfloor\frac{401n}{65536}\right\rfloor+125$ would be the closest one can get to scaling the distribution evenly. However, $$ \begin{array}{rlr} [0,163]&\mapsto&125&\frac{164}{65536}\\ [164,326]&\mapsto&126&\frac{163}{65536}\\ [327,490]&\mapsto&127&\frac{164}{65536}\\ [491,653]&\mapsto&128&\frac{163}{65536}\\ [654,817]&\mapsto&129&\frac{163}{65536}\\ &\vdots \end{array} $$ Thus, we see that $125$ with a probability of $\frac{164}{65536}$ is more likely than $126$ with a probability of $\frac{163}{65536}$, etc.
To get a truly uniform distribution by scaling, we need to draw our initial random numbers from a pool that is distributed over a range that is a multiple of the range we want. Since we have random numbers that are from $0$-$65535$, we can use those to get a uniform distribution from $0$-$65362$ by discarding anything greater than $65362$. This only happens with probability $$ \frac{65536-65362}{65536}=\frac{174}{65536}\doteq0.002655 $$ that is, not very frequently. Now if we take the numbers from $0$-$65362$ and put them through the function $$ \left\lfloor\frac{n}{163}\right\rfloor+125 $$ we will get a uniform distribution on $125$-$525$ since $163\cdot401=65363$. That is, $$ \begin{array}{rlr} [0,162]&\mapsto&125&\frac{163}{65363}=\frac1{401}\\ [163,325]&\mapsto&126&\frac{163}{65363}=\frac1{401}\\ [326,488]&\mapsto&127&\frac{163}{65363}=\frac1{401}\\ [489,651]&\mapsto&128&\frac{163}{65363}=\frac1{401}\\ [652,814]&\mapsto&129&\frac{163}{65363}=\frac1{401}\\ &\vdots \end{array} $$