May I ask how to choose random prime number in fix interval?

11 views (last 30 days)
May I ask how to choose random prime number in fix interval? For example, choose prime number in between 2 to 30...

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 28 Apr 2016
a = 2;
b = 30;
p = primes(b);
p = p(p >= a);
out = p(randperm(numel(p),1));

More Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 28 Apr 2016
a=primes(30);
out=a(a>=2)

Categories

Find more on Elementary Math 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!