assalmualikum guys
is there any function or code to find prime numbers??
i know that its hard to find them but i have to do it??
could u plz help me with that
assalmualikum guys
is there any function or code to find prime numbers??
i know that its hard to find them but i have to do it??
could u plz help me with that
can be done simply using this code
[CENTER]p = primes(n)
[/center]
thank u very much dear friend
second part now
how can i choose randomly 2 large numbers from result of function primes???
i want to choose 2 numbers randomly and they must be large and not equal also,could u plz help me with that
i apperciate all ur help
my best wishes and regards
we can design a function for that but there might be direct method for doing so !! any way i will try my best !!!
alsalmu aleekum
this is a function can do the task and i do believe there is a single command line for these stuff
but this is from the programming prospective
[SIZE=2][FONT=Courier New][SIZE=2][FONT=Courier New]clear[/font][/size]
[SIZE=2][FONT=Courier New]n= input([/font][/size][/font][/size][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'Enter the highest number: '[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[/size][/font]
[SIZE=2][FONT=Courier New]c=primes(n)[/font][/size]
[SIZE=2][FONT=Courier New]y=[0 0];[/font][/size]
[SIZE=2][FONT=Courier New]j=1;[/font][/size]
[/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]while[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] (y(1)== 0) || (y(2)==0)[/color][/size][/font]
[SIZE=2][FONT=Courier New]x=uint32(10*n*rand(1));[/font][/size]
[/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]for[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] i=length(c):-1:1[/color][/size][/font]
[/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (c(i)==x)[/size][/font]
[SIZE=2][FONT=Courier New]y(j)=x;[/font][/size]
[/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2](y(2)==y(1))[/size][/font]
[SIZE=2][FONT=Courier New]y(2)=0;[/font][/size]
[SIZE=2][FONT=Courier New]j=j-1;[/font][/size]
[/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]end[/color][/size][/font]
[/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]j=j+1;[/size][/font]
[/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]else[/color][/size][/font]
[/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]end[/color][/size][/font]
[/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]end[/color][/size][/font]
[SIZE=2][FONT=Courier New][COLOR=#0000ff]end[/color][/font][/size]
[/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]y[/size][/font]
[/size][/font]
buena suerte
[CENTER]this is another code which is much much easier and take less execuation time
clear
n= input('Enter the highest number: ')
c=primes(n)
y=[0 0];
for i=1:2
x=uint32(length(c)*rand(1));
y(i)=c(x);
end
y
[/center]
شوف الامر
out = randseed(state,m,n,rmin,rmax)
see help
thank u very much guys, now it works perfect
u r really very helpful and i apperciate ur response and im very happy 2 be one of ur friends in this forum
my best wishes and regards