Java Random randomVector(int size)

Here you can find the source of randomVector(int size)

Description

Creates a random vector of integers of length size

License

Open Source License

Parameter

Parameter Description
size the length of the random vector

Return

a random vector with elements from 0 to Integer.MAX_VALUE

Declaration

public static int[] randomVector(int size) 

Method Source Code


//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;
    }
}

Related

  1. randomSubList(List list, int sizeOfSubList)
  2. randomSuccess()
  3. randomUniformUniqueIntegerList(int sz)
  4. randomValue()
  5. randomValue(T[] array)
  6. randRandom(Random random)
  7. randRange(float from, float to)
  8. randRangeDecimal(float min, float max)
  9. resetRandomGenerator()