Java Random Int randomInt(int ceil)

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

Description

Returns a random number between 0 and the int you pass

License

Apache License

Parameter

Parameter Description
ceil Max value for the random number

Return

Random number

Declaration

public static int randomInt(int ceil) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.*;

public class Main {
    /**//from  w w  w  .jav  a 2  s.c  o m
     * Returns a random number between 0 and the int you pass
     *
     * @param ceil Max value for the random number
     * @return Random number
     */
    public static int randomInt(int ceil) {
        Random m = new Random(Calendar.getInstance().getTimeInMillis());
        Random e = new Random(m.nextInt());
        return (int) (e.nextFloat() * (ceil + 1));
    }

    public static int randomInt(int floor, int ceil) {
        return randomInt(Calendar.getInstance().getTimeInMillis(), floor, ceil);
    }

    public static int randomInt(long seed, int floor, int ceil) {
        Random m = new Random(seed);
        Random e = new Random(m.nextInt());
        return (int) (e.nextFloat() * (ceil - floor + 1)) + floor;
    }
}

Related

  1. randomInIntervall(float low, float high)
  2. randomInt(double arg)
  3. randomInt(final int max)
  4. randomInt(final int min, final int max)
  5. randomInt(final int upToNotInclusive)
  6. randomInt(int fromInclusive, int toExclusive)
  7. randomInt(int in)
  8. randomInt(int low, int high)
  9. randomInt(int min, int max)