Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6949181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:55:14+00:00 2026-05-27T13:55:14+00:00

BigInteger q = new BigInteger(8, 10, new Random()); is giving me random numbers as

  • 0

BigInteger q = new BigInteger(8, 10, new Random()); is giving me random numbers as expected every time while running from my Desktop but not in Android.

in Android I am always getting only same output instead of random number. Please help me to get random BigIntegr.

for your info:

int randQ = (int) (Math.random() * 9);      
        for (int r = 0; r < randQ; r++) {

            q = q.nextProbablePrime();
        }

is the quick fix that I did and I am not happy with this fix since it is consuming extra time.
your suggestions are highly appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:55:15+00:00Added an answer on May 27, 2026 at 1:55 pm

    This is a very common problem, independent of language or platform.

    You must reuse the instance of Random() to get random numbers each time. The default constructor will seed the pseudo-random number generator with the current time. The current time doesn’t change very quickly with respect to your program, so you keep getting the same number until the clock ticks up.

    If you don’t re-seed, it will give you different numbers each time you ask for another value. You can avoid re-seeding by reusing the instance, and calling:

    Random random = new Random(); // reuse this instance...
    int value = random.nextInt(); // use these values instead of new Random()
    

    See: http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Random.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

.NET 4.0 now has a new data type, System.Numeric.BigInteger. From what I understand, this
I'm new to Java and just code a program with BigInteger. public static void
using Org.BouncyCastle.Math; string p = E7A69EBDF105F2A6BBDEAD7E798F76A209AD73FB466431E2E7352ED262F8C558F10BEFEA977DE9E21DCEE9B04D245F300ECCBBA03E72630556D011023F9E857F; BigInteger P= new BigInteger(p); throwing Exception System.FormatException: Input
This question: How to generate a random BigInteger describes a way to achieve the
All, I have implemented a code that generates 2 random prime numbers and the
In my android application. I got binary code from a jpeg image from the
I want to use a big integer value in my while loop condition but
From googling around, I found that using while loops or using variables is discouraged.
Is it possible to do +- operations like this somehow? BigInteger a = new
I have a BigInteger value, let's say it is 282 and is inside the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.