Info

This question is closed. Reopen it to edit or answer.

How do I generate random numbers within a certain range a and b but excluding a specific number within this range, let's call this number c?

1 view (last 30 days)
so for example the function has to be randint_reject(a,b,c) where it generates random numbers from a and b but excludes the value of c. if I have a = 2, b = 6, and c = 4. I would generate numbers between 2 and 6 excluding the number 5. This is what I have so far:
function f = ranInt_reject(a,b,c)
randInt_reject = (b-a)*rand + a;
f = randInt_reject;
if f == c
f = c + 1;
else
f = randInt_reject;
end
end
Any help will be highly appreciated, thanks!
  4 Comments
Alex Benavides
Alex Benavides on 14 Nov 2013
It doesn't, I just figured I was being a little ambiguous on the previous one and decided to add some more details, and the reason why I added the monty hall tag is because this is one of the prerequisites I need in order to solve that problem.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!