Here you can find the source of randomVector(int size)
Parameter | Description |
---|---|
size | the length of the random vector |
public static int[] randomVector(int size)
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { private static Random random = new Random(); /**//from w ww . ja va2 s . co m * Creates a random vector of integers of length <em>size</em> * @param size the length of the random vector * @return a random vector with elements from 0 to Integer.MAX_VALUE */ public static int[] randomVector(int size) { return randomVector(size, Integer.MAX_VALUE); } /** * Creates a random vector of integers of length <em>size</em> * @param size the length of the random vector * @param the upper limit (exclusive) on the random numbers * @return a random vector with elements from 0 to max-1 */ public static int[] randomVector(int size, int max) { int[] retVal = new int[size]; for (int i = 0; i < size; i++) { retVal[i] = random.nextInt(max); } return retVal; } }