Java ThreadLocalRandom getRandomFloat()

Here you can find the source of getRandomFloat()

Description

returns (.nextFloat() * 10 ) * (1/2 chance of *= -1)

License

Open Source License

Declaration

public static float getRandomFloat() 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.concurrent.ThreadLocalRandom;

public class Main {
    /**/*  w  w  w. ja va  2  s.c  o m*/
     * returns (.nextFloat() * 10 ) * (1/2 chance of *= -1)
     * 
     * @return
     */
    public static float getRandomFloat() {
        float randomFloat = ThreadLocalRandom.current().nextFloat() * 10;
        float coinFlip = ThreadLocalRandom.current().nextInt(2);
        if (coinFlip > 0) {
            randomFloat *= -1;
        }
        return randomFloat;
    }
}

Related

  1. getRandomBetween(int min, int max)
  2. getRandomBoundedInt(int bound)
  3. getRandomDouble(double a, double b)
  4. getRandomElement(E[] array)
  5. getRandomElement(List elements)
  6. getRandomId(@Nonnull Random random, int length)
  7. getRandomInt()
  8. getRandomInt(int a, int b)
  9. getRandomInt(int limit)