The Math Forum

Search All of the Math Forum:

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

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

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 ]

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,

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

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.