mercredi 1 avril 2020

Java with Randoms Number

i'm a beginners with Java, and i have a problem about generating random numbers. So here's what i wrote :

    int a = 1;
    // 0 to 10
    SecureRandom random = new SecureRandom();
    int shoot1 = random.nextInt(11);
    int shoot2 = random.nextInt(11);


    System.out.print("\nSHOT " + a + ".... Challenger shoots " + shoot1);
    System.out.print("\nSHOT " + (++a) + ".... Challenger shoots " + shoot2);
    System.out.print("\nCHALLENGER SCORE: " + (shoot1 + shoot2));

Is it a way to generate two different number for shoot without having shoot1 and shoot2 ? like is it a way to just have one variable but they generate two different number? When i put one variable is always give me the same number for both of the printed line. Thank you !




Aucun commentaire:

Enregistrer un commentaire