Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

how to randomize an array java

void shuffle(int [] arr) {
        for (int i = 0; i < arr.length; i++) {
            int index = (int) (Math.random() * arr.length);
            int temp = arr[i];
            arr[i] = arr[index];
            arr[index] = temp;
        }
    }
Comment

java random array

import java.util.Random;
public class Example {
   public static void main(String[] args) {
      Random rd = new Random(); // creating Random object
      int[] arr = new int[5];
      for (int i = 0; i < arr.length; i++) {
         arr[i] = rd.nextInt(); // storing random integers in an array
         System.out.println(arr[i]); // printing each array element
      }
   }
}
Comment

PREVIOUS NEXT
Code Example
Java :: java deltaTime 
Java :: How to add negative random numbers in java 
Java :: javax.xml.bind does not exist 
Java :: big screen jframe 
Java :: javaee jsp convert int to string 
Java :: change editext hint color android 
Java :: format localdate java 
Java :: how to get the highest value in a list java 
Java :: how to clear stringbuilder in java 
Java :: bundletool aab to apk 
Java :: spring create bean only if another bean does not exists 
Java :: java cached enum 
Java :: maven compiler plugin for java 13 
Java :: java array kürzen 
Java :: how to parse json array in java 
Java :: java jshell run string as code 
Java :: jpa validation string only number 
Java :: how to set audio of a java sound clip 
Java :: processing load font from file 
Java :: ISO week date java 
Java :: afficher texte java 
Java :: leetcode 416 
Java :: the result o trim is ignored java 
Java :: calculate age from localdate java 
Java :: how to shuffle string java 
Java :: convert set to list java 
Java :: How to efficiently generate all combinations of well-formed parentheses for n pairs of them, in Java? 
Java :: minecraft java arguments 
Java :: java main class 
Java :: how to iterate hashset in java 8 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =