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 ]
Antonio Valentine

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

"Nasser M. Abbasi" wrote in message <krtkdb$oj$1@speranza.aioe.org>...
> On 7/14/2013 1:21 AM, Antonio Valentine wrote:
> > Hello there,
> >
> > Kindly be asked for helping in the coding of how to generate a specific range of random numbers. Here is my question
> >
> > I want to generate an integer number between 1-40.
> >
> > randi(40,1)
> >
> > However, I want to skip some numbers as appeared in this vector [10 13 22 27].
> >
> > How should I do?
> >
> > Thank you in advance.
> >
> >
> > This is what I have done in the past which is unable to scale up. So I would like to ask for suggestions.
> >
> > actor_1 = 10;
> > actor_2 = 13;
> > actor_3 = 22;
> >
> > num_event = 10;
> > num_node = 40;
> >
> > for i = 1 : num_event
> >
> > alarm_node(i) = randi(num_node,1);
> >
> > while alarm_node(i) == actor_1 || alarm_node(i) == actor_2 %|| alarm_node(i) ~= actor_3
> >
> > alarm_node(i) = randi(num_node,1);
> >
> > end
> >
> > end
> >

>
> -----------------------------
> A = [1:9 11 12 13:21 23:26 28:40];
> N = length(A);
> num_event = 10;
> arrayfun(@(i) A(randi(N,1)),1:num_event)
> --------------------------------
>
> 9 37 6 34 21 40 3 18 4 39
>
>
>


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?



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.