mercredi 17 mars 2021

Generate 500 random nmbers between 500 and 2000 without duplicates

I've got this far, now I don't know how get no duplicates

package randomnumbergenerator;

import java.util.Random;


public class Rndm {
    public static void main(String[] args) {
        Random rn = new Random();   
        int lowwerlimit = 500, upperlimit = 2000, myrn;
    
        for (int i=1; i<=500; i++) {
            myrn = rn.nextInt(upperlimit - lowwerlimit + lowwerlimit);
            System.out.println(" Random number  " + i + " : " + " " + myrn);            
        }
    }
}



Aucun commentaire:

Enregistrer un commentaire