Java Random Float Number randFloat(float min, float max)

Here you can find the source of randFloat(float min, float max)

Description

Returns a pseudo-random number between min and max, inclusive

License

Apache License

Parameter

Parameter Description
min Minimum value
max Maximum value. Must be greater than min

Return

float between min and max, inclusive

Declaration

public static float randFloat(float min, float max) 

Method Source Code


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

import java.util.Random;

public class Main {
    /**//from   www  .j  a  v a  2 s  .  c  o m
     * Returns a pseudo-random number between min and max, inclusive
     * @param min Minimum value
     * @param max Maximum value.  Must be greater than min
     * @return float between min and max, inclusive
     */
    public static float randFloat(float min, float max) {
        Random rand = new Random();
        return rand.nextFloat() * (max - min) + min;
    }
}

Related

  1. randFloat(float min, float max)
  2. randFloat(float min, float max, long seed)
  3. randomFloat(float min, float max)