Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: How to generate ONE random number between TWO intervals??
Replies: 5   Last Post: Apr 10, 2013 7:13 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Bill

Posts: 24
Registered: 12/7/04
How to generate ONE random number between TWO intervals??
Posted: Sep 30, 2008 10:19 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hi all,

I need to generate a single random number between two intervals. For
example, how would I use the "rand()" function to generate a random
number between the intervals of: [-2, -1] AND [1,2]. If I needed a
random number between [1,2], I know I can just simply use:

r = a + (b-a).*rand(100,1);

where a=1 and b=2. Any ideas on how to apply this equation to get a
random number between the 2 intervals listed above?

Thanks in advance,
-weg22



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.