Java Utililty Methods Random Int

List of utility methods to do Random Int

Description

The list of methods to do Random Int are organized into topic(s).

Method

intrandomNumber(int min, int max)
Generates a random number
return (int) (Math.random() * max + min);
intrandomNumber(int minimum, int maximum)
random Number
return (int) (Math.random() * maximum + minimum);
intrandomNumberBetweenIntervals(int min, int max)
Returns a random number from the specified range
if (min >= max) {
    throw new IllegalArgumentException("The minimum bound cannot be larger or equal to the maximum bound!");
return min + (int) (Math.random() * ((max - min) + 1));
intrandomNumberWithinRange(int low, int high)
random Number Within Range
int result = (int) (Math.random() * (high - low + 1)) + low;
return result;
IntegerrandomNumberWithinRange(int min, int max)
Returns a random number within the given range.
return ((int) (Math.random() * max)) + min;
StringrandomPass(int n)
Questo metodo viene utilizzato per la generazione di una password Random
String caratteriValidi = "";
String temp = "";
double icasuale = 0;
caratteriValidi += "abcdefghijklmnopqrstuvwxyz0123456789@!";
for (int i = 0; i < n; i++) {
    icasuale = Math.floor(Math.random() * caratteriValidi.length());
    temp += caratteriValidi.charAt((int) icasuale);
return temp;
float[]randomPointInConvexPoly(float[] pts, int npts, float[] areas, float s, float t)
random Point In Convex Poly
float areasum = 0.0f;
for (int i = 2; i < npts; i++) {
    areas[i] = triArea2D(pts, 0, (i - 1) * 3, i * 3);
    areasum += Math.max(0.001f, areas[i]);
float thr = s * areasum;
float acc = 0.0f;
float u = 0.0f;
...
double[][]randomPointsFromFigureEight(int n)
random Points From Figure Eight
if (n <= 0) {
    throw new IllegalArgumentException();
double[][] result = new double[n][2];
for (int i = 0; i < n; i++) {
    double theta = 2 * Math.PI * Math.random();
    double x = Math.cos(theta);
    double y = Math.sin(theta);
...
double[][]randomPointsFromUnitSphere(int n)
random Points From Unit Sphere
if (n <= 0) {
    throw new IllegalArgumentException();
double[][] result = new double[n][3];
for (int i = 0; i < n; i++) {
    double phi = Math.PI * Math.random();
    double theta = 2 * Math.PI * Math.random();
    double x = Math.cos(theta) * Math.sin(phi);
...
double[][]randomPointsFromUnitSquare(int n)
random Points From Unit Square
if (n <= 0) {
    throw new IllegalArgumentException();
double[][] result = new double[n][2];
for (int i = 0; i < n; i++) {
    result[i][0] = Math.random();
    result[i][1] = Math.random();
return result;