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)
Show older comments
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!
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!