Java Random Int randomInt(int in)

Here you can find the source of randomInt(int in)

Description

{ method

License

Apache License

Parameter

Parameter Description
in - choices - non-null non-empty

Return

- one choice }

Declaration

public static int randomInt(int in) 

Method Source Code

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

Related

  1. randomInt(final int max)
  2. randomInt(final int min, final int max)
  3. randomInt(final int upToNotInclusive)
  4. randomInt(int ceil)
  5. randomInt(int fromInclusive, int toExclusive)
  6. randomInt(int low, int high)
  7. randomInt(int min, int max)
  8. randomInt(int mn, int mx)
  9. randomInt(int n)