0
\$\begingroup\$

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

\$\endgroup\$
8
  • \$\begingroup\$ 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? \$\endgroup\$
    – Pikalek
    Feb 2, 2018 at 15:47
  • \$\begingroup\$ @Pikalek , yes this is the idea behind what i want to do constraint the values to specific range \$\endgroup\$ Feb 2, 2018 at 15:53
  • \$\begingroup\$ @ahmedosama I corrected the mistake in your question. Note that you are also able to edit your question yourself. \$\endgroup\$
    – Philipp
    Feb 2, 2018 at 15:55
  • 1
    \$\begingroup\$ 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? \$\endgroup\$
    – Philipp
    Feb 2, 2018 at 15:59
  • \$\begingroup\$ Also, do you need integers or decimal numbers? \$\endgroup\$
    – Pikalek
    Feb 2, 2018 at 16:07

1 Answer 1

1
\$\begingroup\$

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().

\$\endgroup\$
2
  • \$\begingroup\$ 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 \$\endgroup\$ Feb 5, 2018 at 11:36
  • \$\begingroup\$ @ahmedosama Honestly, the resolution formula doesn't make sense to me. M is the number of points in the range, but I'm not sure what that is supposed to mean. If you're dealing with decimal #s, then there are an infinite number of points between any two different min max values. If you have any additional information about the formulas (paper, textbook, tutorial, etc), let me know & I'll see what I can come up with. But without any additional context, I'm not how the resolution is intended to work. \$\endgroup\$
    – Pikalek
    Feb 6, 2018 at 20:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .