Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 06:43 Go to next message
tanveer jaan is currently offline tanveer jaanFriend
Messages: 3
Registered: September 2019
Junior Member
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 17:44 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33252
Registered: July 2009
Senior Member
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).

Ed Merks
Professional Support: https://www.macromodeling.com/
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 10:42 Go to previous messageGo to next message
tanveer jaan is currently offline tanveer jaanFriend
Messages: 3
Registered: September 2019
Junior Member
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 05:01 Go to previous messageGo to next message
Sarika Sinha is currently offline Sarika SinhaFriend
Messages: 132
Registered: February 2010
Location: Bangalore, India
Senior Member
https://stackoverflow.com/questions/58023086/java13-and-eclipse-strange-behaviour

Sarika Sinha
JDT Programmer
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 11:39 Go to previous message
tanveer jaan is currently offline tanveer jaanFriend
Messages: 3
Registered: September 2019
Junior Member
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: Mon Nov 11 17:15:37 GMT 2024

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

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

Back to the top