Sampling value uniformly at random

Dear Mentor,

Could you please guide me the following issue?

The range of r is [-4,0]

so we implement r = -4*np.random.rand() in python.

May i know how to implement in python if range of r is [-3,-1]?

r= ? * np.random.rand()

Thank you

1 Like

Can I know you are asking this computation related to which assignment?

numpy.random.uniform generates random numbers in [low, high).

@Deepti_Prasad Please see this lecture.

Dear Mr Balaji Ambresh,

Thanks for your guidance.

Or if you want to avoid having to read a new documentation page in order to implement Balaji’s method, you could do:

r = 2 * np.random.rand(shape) - 3

So that would give you a range of 2 starting at -3, right?

1 Like

I asked him the assignment so that I can look into his post query.
Thanks for guiding through!!

Dear Mr Paul Mielke,

Thank you so much for your guidance.