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

5 次查看(过去 30 天)
May I ask how to choose random prime number in fix interval? For example, choose prime number in between 2 to 30...

采纳的回答

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

更多回答(1 个)

Azzi Abdelmalek
Azzi Abdelmalek 2016-4-28
a=primes(30);
out=a(a>=2)

类别

Help CenterFile Exchange 中查找有关 Random Number Generation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by