|
I have to really plead ignorance here.
My Dad was a middle school math teacher, but I never
really had a flair for it. I understand what Prime
Numbers are, but I really wasn't sure what was the
right method to find ALL of them, not without burning
out what few brain cells I have that survived the
sixties and early seventies. Anyway, to make a long
story excruciating, I did what I do best - I did a web
search that brought me to a bunch of sites. At first I
thought I was never going to figure it out - there are
some really intense people, and organizations out
there that live for this stuff (give me a break!) -
but, finally I stumbled on http://www.jjam.de/JavaScript/Mathematik/Primzahlen.html
, a German site that posted both the simple code and a
working model of a JavaScript generator that is about
as simple as it gets. Even simple enough for me!
<html>
<head>
<title>Primzahlen-Generator
mit JavaScript</title>
<script
language="JavaScript">
var i, j=0, n=2, prime,
p=new Array();
p[0]=2;
function primes() {
i=0,
prime=true;
while(p[i]*p[i]<=n)
{
if(n%p[i]==0) {
prime = false;
break;
}
i++;
}
if(prime) {
document.primeform.primeinput.value=n;
p[j++]=n++;
setTimeout('primes()',500);
}
else {
n++;
primes();
}
}
</script>
</head>
<body onload="primes()">
<form name="primeform">
<input name="primeinput">
</form>
</body>
</html>
|