# change random number into specific range using resolution

I am having a simple mathematical problem that i would like to scale a randomly created decimal points using numpy , then apply a formula to align this decimal points to range

range $:$- $x_\min : x_\max$

number of points of the interval [xmin : xmax ] : M

number of points to be created : N

$$\\resolution = \frac{(x_\max-x_\min)}{M}$$

equation if found $:$-

$t_s$ $:$- first point

$$\\ t_s = { random * ( x_\max\ - x_\min\ - N*resolution)}\$$

i would like to understand this equation

• Yeah, I just got a similar conclusion. If you substitute the formula for resolution into the formula for ts, the result ts = random * 0 What are the formulas trying to accomplish? The wording sounds like you're trying to constrain your random numbers to be within a given range - is that what you need? Feb 2, 2018 at 15:47
• @Pikalek , yes this is the idea behind what i want to do constraint the values to specific range Feb 2, 2018 at 15:53
• @ahmedosama I corrected the mistake in your question. Note that you are also able to edit your question yourself. Feb 2, 2018 at 15:55
• I still don't understand this question, though. What exactly is the result you expect? As far as I understand, you want N points randomly distributed between Xmin and Xmax. But what is the "resolution" in this context? Feb 2, 2018 at 15:59
• Also, do you need integers or decimal numbers? Feb 2, 2018 at 16:07

If you just want to get a random decimal number selected uniformly from the range [min, max], you can use random.uniform(a, b)
random.uniform(a, b)
Return a random floating point number N such that a <= N <= b for a <= b and b <= N <= a for b < a.
The end-point value b may or may not be included in the range depending on floating-point rounding in the equation a + (b-a) * random().
• Thanks , rando,.uniform(a,b) provide me with good overview also the equation a + (b-a) * random() is so helpful. In above equation it just uses the resolution of the whole interval . i don't know what is the reason for that , do you think that the resolution add any value on the above equation Feb 5, 2018 at 11:36