I have generated a number z from a range (x,y) and want to map z to another range (p,q)
This can be achieved using linear interpolation as seen here: https://www.mathworks.com/matlabcentral/answers/379380-mapping-of-a-random-number-in-one-range-to-another-range
and here:
The relationship I am trying to achieve is similar to this:
01, 02, 03, 04, 05, 06, 07, 08, 09, 10
25, 25, 25, 26, 26, 26, 27, 27, 27, XX
Where the x,y is the range 1-10, p,q is 25-27
If z=7, than the 'equivalent' in the second range would be roughly 27, however this would require one of the intervals to be rounded up or down so it's not totally accurate.
My question is, will linear interpolation achieve the above relationship, and if so, does the relationship 'preserve' the randomness?
For example, if I were to have rolled a die, does the second, interpolated value represent the same 'roll' so to speak, but in the context of a die with more sides?
If you need a deterministic function to map between the two intervals, then in general, as Ethan Bolker points out in his answer and attached comments, one cannot create a perfectly satisfactory map. It can only be done when the number of input values is an integer multiple of the number of output values.
If, however, you can use a probabilistic function, then it can be done, by mapping some input values to two or more output values, in a way that preserves the appropriate probabilities.
For example, suppose you want to map $\{1, 2, 3, 4, 5, 6, 7, 8, 9, 10\}$ to $\{25, 26, 27\}$ in a way that preserves the uniformity and also the ordering of values, as much as possible. That is, we want to define our mapping $f$ so that
Then, we would say $f(1) = f(2) = f(3) = 25$, $f(5) = f(6) = 26$, and $f(8) = f(9) = f(10) = 27$. In addition, we have the following random variables:
$$ f(4) = \begin{cases} 25 & \text{with probability $1/3$} \\ 26 & \text{with probability $2/3$} \end{cases} $$
and
$$ f(7) = \begin{cases} 26 & \text{with probability $2/3$} \\ 27 & \text{with probability $1/3$} \end{cases} $$
This should be straightforward to do in code.