lundi 16 mars 2020

Generate an amount of random numbers from a paramter then store them to call in a method later

I am trying to generate random numbers the amount determined by a paramter then store these numbers so i can assign them to a uniqe id field combined with a string code before e.g user inputs code "HG-" and the number 4 the method will output HG-3981 or HG-8394 etc

My attempt

    {

        for (int i = 0; i == length; i++)
        {
            Random random = new Random();
            int rand = random.nextInt((9 - 1) + 1) + 1;

        }
        System.out.println(prefix + "-" + length);
    }




Aucun commentaire:

Enregistrer un commentaire