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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:27:07+00:00 2026-05-21T07:27:07+00:00

I am receiving an error with this code that pops up Class file editor:

  • 0

I am receiving an error with this code that pops up Class file editor: source not found inside the Random.class tab. It was having issues with my line that says value =…

I am trying to create a general method the generate a random number between the two integers I pass in.

import java.util.Random;

public class RandomNumGen {

    int value;
    Random rand;
    public RandomNumGen() {
        rand = new Random();
    }

    public int intRandom(int min, int max) {
        value = rand.nextInt(max) + min;
        return(value);
    }

    public int choiceRandom(int first, int second, int third, int fourth) {
        int random = intRandom(1, 400);
        if (random < 100) {
            return(first);
        }else if (random > 100 && random < 200) {
            return(third);
        }else if (random > 200 && random < 300) {
            return(fourth);
        }
        return(second);
    }
}

Help would be appreciated,

Thanks

  • 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-21T07:27:08+00:00Added an answer on May 21, 2026 at 7:27 am

    The “source not found” error is because it tried to open the source to java.util.Random to help you debug and couldn’t find it. The code looks right in that it should execute without errors; Random.nextInt will throw an IllegalArgumentException if you pass it a non-positive number, but you’re passing it 400. I don’t get any errors running that code snippet and calling choiceRandom(1, 2, 3, 4);

    However, logically the code is wrong — intRandom doesn’t return a number between min and max. You’re calling nextInt(max), which returns a number between 0 and max-1, and then adding min, making the range between min and min+max-1. You’d need to return rand.nextInt(max-min) + min

    If you just want a method that takes a bunch of integers and returns one at random, a simpler implementation is:

    public int choiceRandom(int... numbers) {
        return numbers[rand.nextInt(numbers.length)];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am not sure what the problem is but I keep receiving this error
I'm receiving this error on a page that previously worked fine, in fact the
I am receiving this error: The ViewData item that has the key 'DepartmentId' is
When uploading an excel file I am receiving this error, can anyone help me?
I'm receiving this error in my Linq statement --- Cannot implicitly convert type 'System.Collections.Generic.IEnumerable'
I am receiving this error. I have no clue as to why it would
I am currently receiving this error: Validation of viewstate MAC failed. If this application
I'm receiving suddenly this error on a Win2003 Server Web Application: Microsoft VBScript runtime
I'm having trouble overriding a ModelForm save method. This is the error I'm receiving:
I am receiving the following error in my code (c#, .Net 3.5, VS2008) when

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.