is there any function to find prime numbers???

hi guys,how r u? wish u best wishes,

guys iwant to implement RSA algorithm in matlab but the hard part is how to find prime numbers from random numbers generated by random function.

is there any way to find prime numbers?? i mean any specific function or code???

i will be more greateful if u can help me with that problem.


  • The function [u]isprime[/u] tell you if a number in a vector is prime or not.
  • i found function called primes and it returns prime numbers for any selected numbers. ok this is very perfect but now i want to choose two large random numbers and they r not equal from result of function primes.... how can i do that??? i tried the following code

    r=randint(1,1,1000000) % here command means generate 1 random numbers between 1 and 1000000
    p=primes(r) % here commands means find prime numbers less than or equal r

    up to here is fine with me but my question is how can i choose randomly two large numbers and they r not equal also??
    i tried
    p=p(1:1000) %i know here select numbers from 1 to 1000

    i really need ur help

    thank u very much
  • I can't understand very well your problem. You have to choose 2 random prime numbers, it's right?

    I think you can do it in this way:
    p=[4 4];
    for i=1:2
    while isprime(p(i))==0

    in this way p is a vector with two random prime numbers.
    Let me know if it is what you want.
  • thank u very much my friend

    u r really amazing

    thank god cuz there is someone like u

    im very greateful and apperciate all ur help

    yes its what i want

  • Thanks a lot. I'm glad I could help.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!