java - Excluding numbers from interval, retrieving the rest -
i want interval of numbers between 0 , 9 using random generator. example, if received 0,2,7 don't want numbers again, instead want 1 of rest between given interval[1 or 3 or 4 or 5 or 6 or 8 or 9].
as boris spider says:
// want numbers between 0 , 9 inclusive int min = 0, max = 9; // need collection, lets use list, use ordered collection here list<integer> nums = new arraylist<>(); // put numbers in collection (int n=min; n<=max; n++) { nums.add(n); } // randomly sort (shuffle) collection collections.shuffle(nums); // pull numbers collection (the order should random now) (int count=0; count<nums.length; count++) { system.out.println("number " + count + " " + nums.get(count)); }
Comments
Post a Comment