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: generate specific random value except some numbers
Replies: 6   Last Post: Jul 15, 2013 5:26 AM

Advanced Search

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

Posts: 5,873
Registered: 12/7/04
Re: generate specific random value except some numbers
Posted: Jul 15, 2013 5:26 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Antonio Valentine" <chanloha@gmail.com> wrote in message <krtkqb$rsc$1@newscl01ah.mathworks.com>...
> Your suggestion is quite straightforward. May I ask for an option of
>
> A = [1:40];
> B = [10 13 22 27];
>
> Then I can separate into two vectors where vector B the numbers I want to skip it.
>
> Is that possible?

- - - - - - - - - - - - -
A = 1:40;
B = [10 13 22 27];

S = setdiff(A,B);
r = S(randi(numel(S),n,1));

where n is the desired number of random values.

Note: This should work for any sets A and B, integer-valued or otherwise, provided their 'setdiff' is not empty.

Roger Stafford



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.