Numerical Recipes Forum  

Go Back   Numerical Recipes Forum > Obsolete Editions Forum > Methods: Chapters 7, 8, and 20

Reply
 
Thread Tools Display Modes
  #1  
Old 05-26-2010, 12:03 AM
smp smp is offline
Registered User
 
Join Date: Dec 2009
Posts: 11
Random Numbers between -0.5 to +0.5

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
Reply With Quote
  #2  
Old 05-26-2010, 11:12 AM
davekw7x davekw7x is offline
Registered User
 
Join Date: Jan 2008
Posts: 368
Quote:
Originally Posted by smp View Post
...numbers between -0.5 to +0.5.
OK
Quote:
Originally Posted by smp
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?
Quote:
Originally Posted by smp
DIRECT method to generate RNs
Anything 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
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 07:56 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.