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 7829799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:55:04+00:00 2026-06-02T10:55:04+00:00

The Java api has a method on how to generate integers between 0(inclusive) and

  • 0

The Java api has a method on how to generate integers between 0(inclusive) and n(exclusive), but does not have a method to generate random numbers of double values, given a certain range, say 2.0 to 3.0. How can this be done?


 double x = 0.7 + Double.valueOf(Math.random()*(9.0-0.7)).intValue(); 

The result its just few numbers of type .7

  • 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-06-02T10:55:06+00:00Added an answer on June 2, 2026 at 10:55 am

    You’re very close, but the intValue() call is unnecessary and the Double.valueOf( String ) call shouldn’t even compile.

    public double random( double min, double max )
    {
      double diff = max - min;
      return min + Math.random( ) * diff;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've read the java api, but I still do not understand the main difference
The java ee 6 api has an annotation @Resource with an attribute 'lookup', however,
I have looked at the Java API for ReentrantLock and what I can see
I have to implement an API for a homework assignment, and my instructor has
The Apache Qpid Java client API has an AMQConnection class that is used to
I have a class that has a fair amount of static variables, not all
I had a look at the java api about GregorianCalendar and did not see
Whenever I have the need to design an API in Java, I normally start
Our company has a very large public Java API which is currently being released
I'm using String.format method of Java API to log something. My method is like:

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.