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

6 vues (au cours des 30 derniers jours)
loong seow li
loong seow li le 28 Avr 2016
Commenté : loong seow li le 28 Avr 2016
May I ask how to choose random prime number in fix interval? For example, choose prime number in between 2 to 30...

Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 28 Avr 2016
a = 2;
b = 30;
p = primes(b);
p = p(p >= a);
out = p(randperm(numel(p),1));
  2 commentaires
loong seow li
loong seow li le 28 Avr 2016
thanks a lot...
loong seow li
loong seow li le 28 Avr 2016
How about if I want to choose two random prime numbers in same interval?

Connectez-vous pour commenter.

Plus de réponses (1)

Azzi Abdelmalek
Azzi Abdelmalek le 28 Avr 2016
a=primes(30);
out=a(a>=2)

Catégories

En savoir plus sur Random Number Generation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by