Results 1 to 5 of 5
  1. #1
    ajay.eeralla is offline Member
    Join Date
    Mar 2011
    Posts
    7
    Rep Power
    0

    Default i want generate random numbor b, but iam getting error

    Java Code:
    package pollardp1;
    import java.math.BigInteger;
    import java.security.SecureRandom;
    import java.util.*;
    import java.io.*;
    /**
     *
     * @author ajay
     */
    public class Pollardp1 {
    private final static BigInteger ZERO = new BigInteger("0");
        private final static BigInteger ONE  = new BigInteger("1");
        private final static BigInteger TWO = new BigInteger("2");
     //private final static SecureRandom random = new SecureRandom();
    
    
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            // TODO code application logic here
    
         System.out.println("Enter a number to be factor");
           Scanner input=new Scanner(System.in);
           BigInteger n=input.nextBigInteger();
           Random rand = new Random();
    
           BigInteger b=lnr(BigInteger.valueOf(rand.nextInt()),n);
            //BigInteger b  = 
            BigInteger r2;
    int i=2;
        BigInteger r=b.mod(n);
        BigInteger gcd=r.subtract(ONE).gcd(n);
        while(true){
         while(gcd.equals(ONE))
         {
          
            
                for(int j=1;j<i;j++)
             {
                 r = r.multiply(r).mod(n);
            gcd=(r.subtract(ONE)).gcd(n);
        }
         i++;
         }
        if(gcd.equals(n))
        {
            System.out.println(ONE + "," + gcd);
            break;
            }
            else
    
        {
            System.out.println(gcd + "," + n.divide(gcd));
            break;
            }
            }
        }}

    Enter a number to be factor
    632887
    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code
    at pollardp1.Pollardp1.main(Pollardp1.java:34)
    Java Result: 1
    BUILD SUCCESSFUL (total time: 14 seconds)
    Last edited by Eranga; 03-11-2011 at 08:54 AM. Reason: code tags added

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Oh yes. What you are trying to do with this?

    Java Code:
    BigInteger b=lnr(BigInteger.valueOf(rand.nextInt()),n);

  4. #4
    ajay.eeralla is offline Member
    Join Date
    Mar 2011
    Posts
    7
    Rep Power
    0

    Default i want generate random numbor b, but iam getting error

    My intension is to generate b is random big integer having number of digits as in n..

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

Similar Threads

  1. [Q] Generate Random Letter
    By iriscience in forum New To Java
    Replies: 11
    Last Post: 01-31-2011, 12:10 AM
  2. Random integer generate
    By trbLeeciN in forum New To Java
    Replies: 6
    Last Post: 06-22-2010, 01:19 AM
  3. Replies: 8
    Last Post: 04-19-2009, 05:50 PM
  4. Trying to Generate Random number
    By PeterFeng in forum New To Java
    Replies: 10
    Last Post: 01-14-2009, 08:37 AM
  5. Generate a random number
    By romina in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 05:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •