Search All of the Math Forum:

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

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

Topic: generate specific random value except some numbers
Replies: 6   Last Post: Jul 15, 2013 5:26 AM

 Messages: [ Previous | Next ]
 Antonio Valentine Posts: 17 Registered: 7/29/12
generate specific random value except some numbers
Posted: Jul 14, 2013 2:21 AM

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?

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

Date Subject Author
7/14/13 Antonio Valentine
7/14/13 Nasser Abbasi
7/14/13 Antonio Valentine
7/14/13 Bruno Luong
7/14/13 Antonio Valentine
7/14/13 Nasser Abbasi
7/15/13 Roger Stafford