Reputation: 1
import java.util.*;
public class NumberGeneratorGame {
public static void main(String args[]) {
double random1 = Math.floor(Math.random()*351);
if (random1 <= 289) System.out.println( (random1) + " You win a blue skin.");
if (random1 >=290 || random1 <=325) System.out.println( (random1) + " You win a purple skin."); //want odds to be from 290-325
if (random1 >=326 || random1 <=340) System.out.println ( (random1) + " You win a pink skin."); //want odds to be 326-340
if (random1 >=341 || random1 <=347) System.out.println ((random1) + " You win a red skin!!!!"); //want odds to be 341 - 347
if (random1 >=348 || random1 <=350) System.out.println ((random1) + " You win a knife!!!!"); //want odds to be 348-350
}
}
I'm trying to make a CSGO Case Opening Simulator type thing. Whenever I execute this though, I get this:
167.0 You win a blue skin.
167.0 You win a purple skin.
167.0 You win a pink skin.
167.0 You win a red skin!!!!
167.0 You win a knife!!!!
Upvotes: 0
Views: 101
Reputation: 773
Your flow of your if's is flawed.
public class NumberGeneratorGame
{
public static void main(String args[])
{
double random1 = Math.floor(Math.random()*351);
if (random1 <= 289)
{
System.out.println( (random1) + " You win a blue skin.");
}
else if (random1 <=325)
{
System.out.println( (random1) + " You win a purple skin."); //want odds to be from 290-325
}
else if (random1 <=340)
{
System.out.println ( (random1) + " You win a pink skin."); //want odds to be 326-340
}
else if (random1 <=347)
{
System.out.println ((random1) + " You win a red skin!!!!"); //want odds to be 341 - 347
}
else if (random1 <=350)
{
System.out.println ((random1) + " You win a knife!!!!"); //want odds to be 348-350
}
else
{
System.out.println ((random1) + " You should never see this error"); // Just here to catch any errors
}
}
}
Upvotes: 1
Reputation: 468
Use &&
instead of ||
if (random1 <= 289) System.out.println( (random1) + " You win a blue skin.");
if (random1 >=290 && random1 <=325) System.out.println( (random1) + " You win a purple skin."); //want odds to be from 290-325
if (random1 >=326 && random1 <=340) System.out.println ( (random1) + " You win a pink skin."); //want odds to be 326-340
if (random1 >=341 && random1 <=347) System.out.println ((random1) + " You win a red skin!!!!"); //want odds to be 341 - 347
if (random1 >=348 && random1 <=350) System.out.println ((random1) + " You win a knife!!!!"); //want odds to be 348-350
Upvotes: 1