This is weird. If the C++ library is so bad I do not understand why
the C++ code in your example is so much clearer than the Java
equivalent with an "endless" loop that is exited in the middle.
If C++ library is so great, can you write by only using standard c++
library code that can do the following (and your code must be simpler,
easier to read, and use only standard library) like I am doing below.
import java.math.*;
import java.util.*;
import java.io.*;
public class Prime {
public static void main(String[] args) throws Exception {
FileWriter fstream = new FileWriter("prime.txt");
BufferedWriter fout = new BufferedWriter(fstream);
PrintWriter out = new PrintWriter (fout);
int bits = 1000;
BigInteger bigInteger;
long start = System.currentTimeMillis();
for (int i = 0; i <= 10 ; i++)
{
bigInteger = BigInteger.probablePrime(bits,new Random());
out.println(bigInteger); out.println();
}
out.flush();
long end = System.currentTimeMillis();
System.out.println("Time for generating ten " + bits +
" bit prime numbers " + (end - start) + " ms");
}
}
Here is what it does: it generates ten 1000 bit prime numbers and
writes them to a file. (1000 bit means an integer with 301 digits in
it)
I ran it a a few times with such results...
Time for generating ten 1000 bit prime numbers 10203 ms
Time for generating ten 1000 bit prime numbers 17031 ms
Time for generating ten 1000 bit prime numbers 10172 ms
Time for generating ten 1000 bit prime numbers 11859 ms
Pleas show us the greatestness and simplicity of c++ standard library.
The out file (prime.txt) must look something like this with ten 100
bit prime numbers
----------- out put file (prime.txt) -------
6842254723349861748843666511662064828566534876628355397638542250959845743665351697255227934848482156894344866523784140126158352565945309867555596955179264268811303554610623299537017559218520998260126890669421170013094553214112988499526676482375353071911923101533507666402744156824755893599999340100039
9848648321151813357308534835626628679476461098165407388222336517490832458510672926299515789763227094026404809330108514662634001376874600327941826767246662005353936332269956613789129055242420454444820541158542651993392376425752312667969524325104139501376021913506959016046209547633260919705554429116957
7472464841209790781263623636615796696063008849158951320705532274543716175088447511478468738217459047280793122730986618530055469990170520637092471861656573404083673652252269395461121964962449683983703396496919624484535816579596847010140874266510985075440815394009983327150954852554698319713533791379351
10307661443841358703042499578335475669167539597638484071670840598460024065841392388829670463069085621250998375017313225187317191877437158721006546183087715067594632510292725466539662500002942009673358846734158857335390525432059296521738149709276331297942660035069645233021137424691400274642262813431743
9646399560455185301694828954906916750070648884857568971541459965770127506827253896121786333961281514135550865127250883333128665493840144605606702030252187296380861010724701091267251600797671154006173275374031756032389190673745898442648752134149486082663634202932288789638592154181262596505399198011499
5464104522187331267329792036943268562163662010826313167428236682292212471251253006159887248307492520536268339671206975636852612170286701846188506774200950309204678396738030162734821967950815398661534482769013763609307661014299189641931894663947535991003827610799697457317398005165341572114298969132119
8986916642188317055291435981557704758000970125943137197423439011525746036858282058344569686780852367757142493701994974271668292544581187527833663068924064401318327687566631978430854275350631507711906132491563930688957812901670932635095508760182677873923763628550923736738960671141108239714134899091859
6276685657926620279750831368313993843997469170105733612426682064744233764253914510057013843677656897638995342919260837956656593014230080133856778022055834763450499251347519655724230815974026067377317921799884910111659789204289025730212592107153924529970395158800961403239639973965644599264075923930743
6449473976940431985705116754023412206599611211984444557518153003140889617962537549197822342902685017344039507691145617625401593677823468136459328816011488688129050967390081901875306435168437003180364852877442035556030261006234175552168158246917246372733828393566865962430827532447416329242048968871133
9645462584641815985614567406765522289079385813376636777793253379649956921522143430515943252559790984289447485824485113580733229462265055509626681725512500798566395525436509873858977920237106477382712460314593005451787339196973168859381882333749970132286581447238781845665557466187650302560420122262091
6626649154643032194352836291684124036601901792249879123472876930930421377935289346502117906223474899887619118266933602848811210940591903741366432700900655773229650015847218925624874926977718157361713877846498350708402180443241389168320875916982789784809118258057259463970197729735869840964768378134459