java - Generating two prime numbers of a certain size that are not equal -


i have loop generate 2 prime numbers, don't want them equal , both need exactly "digits" digits. can first prime number (bigint1) of required length, second 1 (bigint2) varies "digits" "digits + 1" , have no idea why, have spent many hours looking @ code , can't find solution, can help?

... public static biginteger[] bigints = new biginteger[2]; static int digits;   public static void generateprimebigint(string stringdigits){      digits = integer.parseint(stringdigits);     int bits = (int)math.ceil(math.log(math.pow(10,digits))/(math.log(2))); // convert digits bits      // generate huge prime random number 1 - 2^(-1000) probability of being prime     biginteger bigint1 = new biginteger(bits,1000,new random(system.currenttimemillis()));     biginteger bigint2 = new biginteger(bits,1000,new random(system.currenttimemillis()));      while (bigint1.tostring().length() != digits){         bigint1 = new biginteger(bits,1000,new random(system.currenttimemillis()));         }       // make sure no 2 bigintegers same     while(bigint1.equals(bigint2)){         biginteger bigint21 = new biginteger(bits,1000,new random(system.currenttimemillis()));         bigint2 = bigint21;         if ((bigint2.tostring().length()) != digits){             while (bigint2.tostring().length() != digits){                 biginteger bigint22 = new biginteger(bits,1000,new random(system.currenttimemillis()));                 bigint2 = bigint22;             }         }     }      // store results in array future reference , display results in rsawindow      rsawindow.setmylabels(5, "here 2 prime numbers, p , q,              of " + digits + "digits");     bigints[0] = bigint1;     rsawindow.setmylabels(7,"p= " + bigint1.tostring());     bigints[1] = bigint2;     rsawindow.setmylabels(8,"q= " + bigint2.tostring()); } 

the constructor biginteger uses length in bits. not same number of decimal digits every time convert new number binary decimal.

[edit] said before made no sense. fixed.

a possible solution rid of if, , add first while loop:

while (bigint1.equals(bigint2) || bigint2.tostring().length() != digits) 

however seems heavyweight piece of code. trying accomplish?


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -