how can i generate a random number out of a range??
Show older comments
i need to generate a random number out of a range, i did it inside with r=-1+(2).*rand(1,1) %my interval is (-1;1)
how can i do to get a random number that is not in this interval?? i mean, a number which satisfy r<-1 U 1<r
Accepted Answer
More Answers (1)
Amit
on 21 Jan 2014
A = [1/rand -1/rand];
r = A(randi(2));
(or)
r = [1/rand -1/rand]*(randperm(2,2) -1)';
Either will generate a random number from r<-1 U 1<r
Categories
Find more on Random Number Generation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!