Here you can find the source of randomInt(int in)
Parameter | Description |
---|---|
in | - choices - non-null non-empty |
public static int randomInt(int in)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { public static final Random gRandomizer = new Random(System.currentTimeMillis()); /**{ method//from w ww . j a v a2 s . c o m @name randomElement @function - choose an element of an array at random @param in - choices - non-null non-empty @return - one choice }*/ public static int randomInt(int in) { if (in <= 1) { if (in == 1) return (0); throw new IllegalArgumentException("randomInt must take a number > 1"); } int test = gRandomizer.nextInt(in); if (test < 0) test = -test; return (test); } }