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

  • Home
  • SEARCH
  • 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 7640167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:36:14+00:00 2026-05-31T08:36:14+00:00

I have seen posts which explains pretty much this question but they all used

  • 0

I have seen posts which explains pretty much this question but they all used integer values and I honestly do not fully understand it hence this question:

I am trying to generate random numbers from the range (-1554900.101) to (52952058699.3098) in java and I was wondering if anyone could explain this to me as I really want to understand it.

My thoughts:
will this be a right approach?
1) Generate a random integer number within my specified range
2) Divide the generated number by pi to get float/double random results

Thanks in advance.

  • 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-31T08:36:15+00:00Added an answer on May 31, 2026 at 8:36 am

    Here’s the idea. You want a random number in a range, let’s say [-1.1,2.2], to start with a simple example. That range has length 3.3 since 2.2 - (-1.1) = 3.3. Now most “random” functions return a number in the range [0,1), which has length one, so we have to scale our random number into our desired range.

    Random random = new Random();
    double rand = random.nextDouble();
    double scaled = rand * 3.3;
    

    Now our random number has the magnitude we want but we must shift it in the number line to be between the exact values we want. For this step, we just need to add the lower bound of the entire range to our scaled random number and we’re done!

    double shifted = scaled + (-1.1);
    

    So now we can put these parts together in a single function:

    protected static Random random = new Random();
    public static double randomInRange(double min, double max) {
      double range = max - min;
      double scaled = random.nextDouble() * range;
      double shifted = scaled + min;
      return shifted; // == (rand.nextDouble() * (max-min)) + min;
    }
    

    Of course, this function needs some error checking for unexpected values like NaN but this answer should illustrate the general idea.

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

Sidebar

Related Questions

Have seen multiple posts on this but I can't see any which answer my
I have seen many posts on this subject, but none have been answered, and
I have seen several posts similar to this but none with a strait forward
I have seen a few posts regarding this issue but not one specific to
I have seen many posts about this problem but didn't get an answer. I
I have seen other posts on this site with answers, but I think I
I have seen other posts , but they are mostly in C#. For someone
I have seen this post which explains how to get the number of milliseconds
I have seen posts which would fetch you pivot results but not unpivot, Need
Ok I have seen many posts on this script. Which can be found..... http://www.white-hat-web-design.co.uk/blog/resizing-images-with-php/

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.