Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » How do I generate random integers within a specific range in Java?
How do I generate random integers within a specific range in Java? [message #1814815] Thu, 19 September 2019 02:43 Go to next message
Eclipse UserFriend
How do I generate a random int value in a specific range?

I have tried the following, but those do not work:

Attempt 1:

randomNum = minimum + (int)(Math.random() * maximum);
// Bug: `randomNum` can be bigger than `maximum`.
Attempt 2:

Random rn = new Random();
int n = maximum - minimum + 1;
int i = rn.nextInt() % n;
randomNum = minimum + i;
// Bug: `randomNum` can be smaller than `minimum`.
Re: How do I generate random integers within a specific range in Java? [message #1814865 is a reply to message #1814815] Fri, 20 September 2019 13:44 Go to previous messageGo to next message
Eclipse UserFriend
This isn't a forum for asking general Java questions but rather for asking questions about Eclipse's Java Development Tools. Try something like StackOverflow (and only if Google doesn't answer your question).
Re: How do I generate random integers within a specific range in Java? [message #1814881 is a reply to message #1814865] Sat, 21 September 2019 06:42 Go to previous messageGo to next message
Eclipse UserFriend
Ed Merks wrote on Fri, 20 September 2019 17:44
This isn't a forum for asking general Java questions but rather for asking questions about Eclipse's Java Development Tools. Try something like StackOverflow (and only if Google doesn't answer your question).



Ok thank you for your kind reply I have a java issue also present.

I'm trying to use Java 13 with Eclipse on Linux. I'm trying to create a 'portable' java+eclipse folder, that can be moved between machines.

Eclipse from https://www.eclipse.org/downloads/download.php?file=/eclipse/downloads/drops4/S-4.13RC1-201908281800/eclipse-SDK-4.13RC1-linux-gtk-x86_64.tar.gz

and inside the eclipse market place I have installed all the parts of https://download.eclipse.org/eclipse/updates/4.13-P-builds

I have set the jdk to the jdk13 folder. The result is that Eclipse can compile my Java13 code, but not run it. When I try to run I get

[..]/EclipseJava13/jdk-13/bin/java: symbol lookup error: [..]/EclipseJava13/jdk-13/bin/java: undefined symbol: JLI_InitArgProcessing
I can compile and run Java13 from command line no problem using commands:

../../../jdk-13/bin/javac --release 13 --enable-preview main/Main.java
../../../jdk-13/bin/java --enable-preview main.Main
If I cut-paste the *.class generated by eclipse I can run them using command

../../../jdk-13/bin/java --enable-preview main.Main
no problem. Thus Eclipse is recognizing Java 13 and is correctly compiling Java 13 code.

But... when I try to run from inside Eclipse, I get that error. I'm not sure what to do next.
Re: How do I generate random integers within a specific range in Java? [message #1814925 is a reply to message #1814881] Mon, 23 September 2019 01:01 Go to previous messageGo to next message
Eclipse UserFriend
https://stackoverflow.com/questions/58023086/java13-and-eclipse-strange-behaviour
Re: How do I generate random integers within a specific range in Java? [message #1814954 is a reply to message #1814925] Mon, 23 September 2019 07:39 Go to previous message
Eclipse UserFriend
Sarika Sinha wrote on Mon, 23 September 2019 05:01
https://stackoverflow.com/questions/58023086/java13-and-eclipse-strange-behaviour



Ok, Thank you so much, I got the answer there, love to be her on this forum.
Previous Topic:Java enable-preview
Next Topic:How to use different classpath variables for different OS's installed?
Goto Forum:
  


Current Time: Sun Aug 31 08:24:21 EDT 2025

Powered by FUDForum. Page generated in 0.03775 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top