Random Numbers between -0.5 to +0.5


smp
05-26-2010, 12:03 AM
Hi,

I want to generate random numbers between -0.5 to +0.5.

I am using ran1() function, first to generate random numbers between 0.0 and 1.0.

Then I subtract 0.5 from each of these random numbers and then the result is multiplied by 10.

Is this trick a good one, as far as random numbers will be used for scientific purpose.

If not, please let me know the better one.

Or, is there any DIRECT method to generate RNs between -N to +N i.e. without "scaling thing mentioned above"?

Thanks,
smp

davekw7x
05-26-2010, 11:12 AM
...numbers between -0.5 to +0.5.OK

I am using ran1() function, first to generate random numbers between 0.0 and 1.0.

Then I subtract 0.5 from each of these random numbers and then the result is multiplied by 10.So: that gives numbers between -5.0 and +5.0, right? Which range do you really want?

DIRECT method to generate RNsAnything is possible, but the usual method (using any kind of library function that I have ever used) is to start with uniformly distributed variates between zero and one or with integer values between zero and some maximum value, either of which could then be scaled to another fixed-point range or a floating-point range.

Why would you want a custom version for a particular range?


Regards,

Dave