generate Random value array - Java Collection Framework

Java examples for Collection Framework:Array Random Value

Description

generate Random value array

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        int size = 2;
        int range = 2;
        System.out.println(java.util.Arrays.toString(genRandomMas(size,
                range)));/*from  ww  w . j a v  a 2s .  c  o m*/
    }

    public static int[] genRandomMas(int size, int range) {
        int[] mas = new int[size];
        for (int i = 0; i < mas.length; i++) {
            mas[i] = (int) (Math.random() * range);
        }
        return mas;
    }
}

Related Tutorials