im not sure how to code the generated a random number from 100 to 150 inclusive for an applet
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
im not sure how to code the generated a random number from 100 to 150 inclusive for an applet
What have you tried? What did google tell you?
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
in goggle i found
int Low = 10;
int High = 100;
int R = r.nextInt(High-Low) + Low;
but r.nextInt(High-Low) + Low i know isnt applet
...what?
Please see the link in my signature on asking smart questions.
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
Lesson: Applets (The Java™ Tutorials > Deployment)
import javax.swing.JApplet; import javax.swing.SwingUtilities; import javax.swing.JLabel; public class HelloWorld extends JApplet { //Called when this applet is loaded into the browser. public void init() { //Execute a job on the event-dispatching thread; creating this applet's GUI. try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { JLabel lbl = new JLabel("Hello World"); add(lbl); } }); } catch (Exception e) { System.err.println("createGUI didn't complete successfully"); } } }
Please use [highlight=Java] code [/highlight] tags when posting your code.
Forum Tip: Add to peoples reputation by clicking the button on their useful posts.
if java.util.Random is available in applet environment then i don't see a problem. The thing is r.nextInt() where r is an instance of Random, produces negative value. So to produce a number between 100 and 150 inclusive u do is this:
if i misunderstood ur problem then sorry, very much sorry.int a = r.nextInt() % 151 ; a = a > 0 ? a : -1 * a ; // making it positive if (a > 150){ a %= 150 ; // cutting down to size if (a < 100) a += 100 ;
Last edited by dumb_terminal; April 12th, 2011 at 03:06 PM.
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
i used this code on my hide and seek college project, where a certain circle will randomly display on the specified playing area.
my playing area is g.fillRoundRect(245,185,280,280,15,15);
it was adjusted so that it will not touch its border.
ranX = 1 + (int)((530-260)*Math.random()+245);
ranY = 1 + (int)((460-190)*Math.random()+175);
Please check the date of the thread and the date of the last post. If the last post is older than ~3 weeks, it's dead. Let it rest in peace.
Thread closed.
KevinWorkman (February 18th, 2014)