Making a random int - Printable Version +- BP Forums (https://bpforums.info) +-- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=55) +--- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=56) +---- Forum: Java (https://bpforums.info/forumdisplay.php?fid=19) +----- Forum: Programming Help (https://bpforums.info/forumdisplay.php?fid=30) +----- Thread: Making a random int (/showthread.php?tid=826) |
Making a random int - mustafa6155 - 03-23-2014 Hello I've got this code, and I hope you can help me out a little bit. [code2=java]import java.util.Random; public class objectIntro { public static void main(String[] args) { String a = "blabla"; String b = "lala"; Random weight = new Random(); //Random rnd = new Random(); //System.out.println("The weight is: " + rnd.weight(100)); if(weight <= 55) { System.out.println(b + "is slimmer then: "+ a); }else if(weight >= 80) { System.out.println(a + " is fatter then: "+ b); } } }[/code2] So what does not work? I want to make the weight int. random and later it can show who is fatter/smaller. Like the output: The weight it: (random generated) 83 blabla is fatter then lala please help me. GRTZ, - mustafa6155 Re: Making a random int - Fusion - 03-29-2014 [code2=java]public static int randInt(int min, int max) { // Usually this can be a field rather than a method variable Random rand = new Random(); // nextInt is normally exclusive of the top value, // so add 1 to make it inclusive int randomNum = rand.nextInt((max - min) + 1) + min; return randomNum; }[/code2] Source from http://stackoverflow.com/questions/363681/generating-random-numbers-in-a-range-with-java |