mercredi 6 juillet 2016

How to Generate Integer Array with random numbers having difference of some fixed size between each?

I want to generate an ArrayList of some size (say 20), and defenite incremeent ratio (say 10).

ArrayList<Integer> arrayList= new ArrayList(20, 10);

While populating this ArrayList,

  • Every Number in the list must be a Random number. (ie. not same always)
  • Number must be 4 digit long. [1000- 9999]
  • There must be some minimum difference between them.

eg.:

minimum difference= 8;
one random number generated is= 1470,

then other numbers generated must not include, any number between [1462-1478].

ie. no any number in range of minimum difference.




Aucun commentaire:

Enregistrer un commentaire