java - Generate more than one random numbers using native or built-in function -


i know generating random number there random function in java

for example          int randomnumber = ( int )( math.random() * 9999 ); 

which generate randomnumber [0,9999] returns 1 number given range.

but want know if there built in function or can native function generate more 1 random numbers , should not match each other

suppose above example if want generate 4 number

it return 1,10,50,5544

here can see there 4 random number , not matching each other .

try

create arraylist , add random number , while adding check if arraylist contains number or not.

eg:

arraylist<integer> numbers = new arraylist<integer>(); while (numbers.size()<=your_max_size) {     int randominteger = ( int )( math.random() * 9999 );     if (!numbers.contains(randominteger)) {     {        numbers.add(randominteger);     } } 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -