For creating object you need to do

Random rand=new Random();

You have forgotten to add () in this line rand = new Random;

Answer from SpringLearner on Stack Overflow
🌐
Reddit
reddit.com › r/eclipse › import cannot be resolved of java.util.random
r/eclipse on Reddit: Import cannot be resolved of java.util.Random
November 17, 2022 -

Heya,

Very new to Java programming, so was testing out a bunch of stuff (thanks to the official docs and yt videos that *may* be outdated as they were posted about 2 to 3 years ago.

I was trying to use the import java.util.Random;to no avail; it's up there in the JRE as a .class in the Package Explorer (under JRE System Library [jdk-19] > java.base > java.util > Random.class ; I suppose that's the correct path) ; also tried the ava.util.random.*;as that seems to be the suggested one by Eclipse.

Installed both 17 & 19 jdk, this is what it looks like on my end. I have been looking around the internet for an hour now without any answer to this problem. Tried Project > Clean...; didn't help - changed the library from 19 to 17, same issue.

Thanks for any answer that could help!

🌐
The Eclipse Foundation
eclipse.org › forums › index.php › t › 977889
Eclipse Community Forums: Newcomers » Can´t seem to import java.util.Random | The Eclipse Foundation
February 3, 2015 - The Eclipse Foundation - home to a global community, the Eclipse IDE, Jakarta EE and over 350 open source projects, including runtimes, tools and frameworks.
Discussions

java - I get errors from code copied from internet - Stack Overflow
Random cannot be resolved into a type - You need to import Random (e.g. import java.util.Random;). More on stackoverflow.com
🌐 stackoverflow.com
April 2, 2012
OH3 rules DSL: Random cannot be resolved to a type
Generating random numbers in rules doesn't seem to work for me. A rule simply doing this: import java.util.Random returns the following in my log: The method or field import is undefined; line ... More on github.com
🌐 github.com
1
December 15, 2020
randomly Broken imports - type from JDK cannot be resolved
I often get errors about not detected classes, for example: java.util.IdentityHashMap cannot be resolved to a type today I even had error on System.out. Cleaning or refreshing doesn't help, but res... More on github.com
🌐 github.com
50
August 30, 2024
cannot be resolved to a variable
Marcus Pierce is having issues with: At the end of the first lesson of Pretty Little Things I get an error that prevents me from running the app. The error is "answer cannot be reso... More on teamtreehouse.com
🌐 teamtreehouse.com
10
June 10, 2014
🌐
GitHub
github.com › openhab › openhab-core › issues › 1935
OH3 rules DSL: Random cannot be resolved to a type · Issue #1935 · openhab/openhab-core
December 15, 2020 - Generating random numbers in rules doesn't seem to work for me. A rule simply doing this: import java.util.Random returns the following in my log: The method or field import is undefined; line ...
Author   openhab
🌐
Coderanch
coderanch.com › t › 602134 › Random-type
Cannot use Random type (Android forum at Coderanch)
October 9, 2016 - I'm using Eclipse Juno, 20121004-1855 with Android SDK at API level 17. Not sure what other information would be needed to resolve this error. Any help is greatly appreciated! Effel ... Sorry for bother you guys, I just found the solution: I should have imported java.util.Random, rather than android.util.Random!
🌐
GitHub
github.com › eclipse-jdt › eclipse.jdt.core › issues › 2877
randomly Broken imports - type from JDK cannot be resolved · Issue #2877 · eclipse-jdt/eclipse.jdt.core
August 30, 2024 - I often get errors about not detected classes, for example: java.util.IdentityHashMap cannot be resolved to a type today I even had error on System.out. Cleaning or refreshing doesn't help, but restarting Eclipse fixes that.
Author   eclipse-jdt
🌐
Team Treehouse
teamtreehouse.com › community › cannot-be-resolved-to-a-variable
cannot be resolved to a variable (Example) | Treehouse Community
June 10, 2014 - package com.example.crystalball; import java.util.Random; public class CrystalBall { public String getAnAnswer() { String[] answers = { "It is certain", "It is decidedly so", "All signs say YES", "The stars are not aligned", "My reply is no", "It is doubtful", "Better not tell you now", "Concentrate and ask again", "Unable to answer now" }; // The button was clicked, so update the answer label with an answer String answer = ""; Random randomGenerator = new Random(); int randomNumber = randomGenerator.nextInt(answers.length); answer = answers[randomNumber]; return answer; } }
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 62622817 › javafx-how-can-i-use-import-java-util-random-cannot-resolve-symbole-java
intellij idea - JavaFX, How can I use "import java.util.Random;", 'Cannot resolve symbole "java".' under Gradle - Stack Overflow
I just need a random variable, but when i try to import something from java... I got this error. Im working with gradle, javafx and intelliJ. When I try to "/gradlew build" I got the same...
🌐
HatchJS
hatchjs.com › home › the import java.util cannot be resolved: causes and solutions
The Import java.util Cannot Be Resolved: Causes and Solutions
January 5, 2024 - To resolve this issue, you need to add the path to the subpackage to the `CLASSPATH` environment variable. The import java.util cannot be resolved error can be a frustrating problem, but it is usually easy to resolve.
🌐
Stack Overflow
stackoverflow.com › questions › 4322893 › eclipse-error-the-import-xxx-cannot-be-resolved › 62704034
java - Eclipse error: "The import XXX cannot be resolved" - Stack Overflow
I could save the java source code it would get rid of the errors but upon rebuilding it, all the errors would come back. ... eventually, the root cause was, I was running in windows and the project folder had read-only access, and all I had to do was open eclipse with administrative access, and after clean build, all imports were resolved.
🌐
OpenJDK
bugs.openjdk.org › browse › JDK-8265137
[JDK-8265137] java.util.Random suddenly has new public ...
April 13, 2021 - But the extension of class jdk.internal.util.random.RandomSupport.AbstractSpliteratorGenerator brings some other problems: As the class is in another package, it implements some public methods (with some intro comment "Required by AbstractSpliteratorGenerator" - so implementor knows that's something strange): https://github.com/openjdk/jdk/blob/a0ec2cb289463969509fe508836e3faf789f46d8/src/java.base/share/classes/java/util/Random.java#L618-L626 Those methods are marked by the Javadoc tag @hidden. So they are nowhere documented and are implementation details. But those methods are still visible as public methods and also shown by IDE tools during autocomplete! The following code compiles!!!: import java.util.Random; public class RandomTest { public static void main(String...
🌐
Stack Overflow
stackoverflow.com › questions › 50053957 › rand-ints-cannot-be-resolved-when-used-in-a-function
java - Rand Ints cannot be resolved when used in a function - Stack Overflow
April 27, 2018 - It has nothing to do with random numbers. The problem is that you initialize answer1 and answer2 inside a loop. If you initialize a variable inside of the loop it doesn't exist outside of the loop.
🌐
JetBrains
youtrack.jetbrains.com › issue › IDEA-302840 › Strange-compilation-error-with-javautilRandom-and-Java-17
Strange compilation error with java.util.Random and Java 17
{{ (>_<) }} This version of your browser is not supported. Try upgrading to the latest stable version. Something went seriously wrong
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › docs › api › java.base › java › util › random › package-summary.html
java.util.random (Java SE 17 & JDK 17)
April 21, 2026 - The set of algorithms required by Java SE may be updated by changes to the Java SE specification. Over time, new algorithms may be added and old algorithms may be removed. In addition, as another life-cycle phase, an algorithm may be deprecated. A deprecated algorithm is not recommended for use. If a required algorithm is deprecated, it may be removed in a future release. Due to advances in random number generator algorithm development and analysis, an algorithm may be deprecated during the lifetime of a particular Java SE release.
🌐
Reddit
reddit.com › r/learnprogramming › [java] the import java.util.math cannot be resolved
r/learnprogramming on Reddit: [Java] The import java.util.Math cannot be resolved
February 13, 2014 -

I'm writing a program to calculate the wind chill based on a temperature and wind speed entered by the user. The formula to calculate wind chill is

Wind Chill = 35.74 + 0.6215T - 35.75V0.16 + 0.4275TV0.16

My current code is

import java.util.Scanner;
import java.util.Math;
public class WindChill {

public static void main(String[] args) {
	
	//Declare variables

	double windChill;
	double temperature;
	int    windSpeed;

//Ask the user for temperature and wind speed

System.out.print("Enter the temperature (Fahrenheit):  ");
	Scanner input = new Scanner (System.in);
	temperature = input.nextDouble();

System.out.print("Enter the wind speed(mph):  ");
	windSpeed = input.nextInt();

	
//Display the wind chill value

windChill = (35.74+(0.6215*temperature)) - (Math.pow(35.75*windSpeed,0.16)) + (Math.pow(0.4275*temperature*windSpeed,0.16));	
System.out.print("The wind chill index is " + windChill);
}

}

I get an error in the IDE on line 2 that says "the import java.util.Math could not be resolved". Also, when I try to run the program, I get the error message

"Exception in thread "main" java.lang.Error: Unresolved compilation problem: 

at WindChill.main(WindChill.java:6)

I checked my installed JREs and I am using JRE7. Can anybody tell me what is wrong?

🌐
GeeksforGeeks
geeksforgeeks.org › java › java-util-random-nextint-java
Java.util.Random.nextInt() in Java - GeeksforGeeks
March 21, 2025 - Explanation: In this program, we try to generate the random numbers but we pass a negative bound which will throw the exception as shown in the image output. Range: This method returns an integer value in the range of in which is from -2^31 to 2^31 - 1. ThreadLocalRandom: For multithreaded environments, it's better to use the ThreadLocalRandom class which is thread-safe. java.security.SecureRandom: Although this method gives the random integer values for better security we can use the alternative SecureRandom which returns the cryptographically secure random numbers.