java - Generating a random number from the array -


suppose there array :

int arr[] = {0,1,2} 

is there way can generate random number out of 0,1,2 (i.e array) ?

try this

    import java.util.random;      random random = new random();     system.out.println(arr[random.nextint(arr.length)]); 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -