Example usage for org.apache.commons.lang.math RandomUtils nextFloat

List of usage examples for org.apache.commons.lang.math RandomUtils nextFloat

Introduction

In this page you can find the example usage for org.apache.commons.lang.math RandomUtils nextFloat.

Prototype

public static float nextFloat() 

Source Link

Document

Returns the next pseudorandom, uniformly distributed float value between 0.0 and 1.0 from the Math.random() sequence.

Usage

From source file:MainClass.java

public static void main(String[] args) {
    //Random Value Generation
    System.out.println("Random double >>> " + RandomUtils.nextDouble());
    System.out.println("Random float >>> " + RandomUtils.nextFloat());
    System.out.println("Random int >>> " + RandomUtils.nextInt());
}

From source file:MathUtilsTrial.java

public static void main(String[] args) {

    // Random Value Generation
    System.out.println("Random double >>> " + RandomUtils.nextDouble());
    System.out.println("Random float >>> " + RandomUtils.nextFloat());
    System.out.println("Random int >>> " + RandomUtils.nextInt());

}

From source file:com.noxpvp.mmo.abilities.entity.MaliciousBiteAbility.java

public boolean execute(EntityDamageByEntityEvent event) {
    if (!mayExecute())
        return false;

    if (!(getEntity() instanceof Tameable))
        return false;

    AnimalTamer a = ((Tameable) getEntity()).getOwner();

    if (a == null || !(a instanceof Player))
        return false;

    Player o = (Player) a;//ww  w.j  a  va  2  s.c  o  m

    PlayerClass pClass = PlayerManager.getInstance().getPlayer(o).getPrimaryClass();

    return RandomUtils.nextFloat() < (pClass.getCurrentTierLevel() * pClass.getLevel()) / 1000;
}

From source file:com.noxpvp.mmo.abilities.player.ParryAbility.java

public boolean execute(EntityDamageByEntityEvent event) {
    if (event.getEntity() != getPlayer() || !mayExecute())
        return false;

    Player p = getPlayer();//  ww  w.java 2 s .  c o m

    MMOPlayer mmoPlayer;

    if ((mmoPlayer = PlayerManager.getInstance().getPlayer(p)) == null
            || (mustBlock && (!parriedWeapons.contains(p.getItemInHand().getType()))))
        return false;

    float chance = mmoPlayer.getPrimaryClass().getTotalLevel() / 6;
    percentChance = (chance <= 75) ? chance : 75;
    if (RandomUtils.nextFloat() > percentChance)
        return false;

    Entity damager = event.getDamager();
    if (damager instanceof Damageable) {
        ((Damageable) damager).damage(event.getDamage() / .7, p);
    }

    return true;
}

From source file:com.epam.catgenome.util.BlockCompressedDataStreamsTest.java

private void doWrite(BlockCompressedDataOutputStream outputStream) throws IOException {
    outputStream.writeFloat(RandomUtils.nextFloat());
    outputStream.writeDouble(RandomUtils.nextDouble());
    outputStream.writeLong(RandomUtils.nextLong());
    outputStream.writeInt(RandomUtils.nextInt());
    outputStream.writeShort(0);//from   w ww  .  j av  a2s .  co m
    outputStream.writeBoolean(RandomUtils.nextBoolean());
    outputStream.writeBytes("test");
    outputStream.writeByte(RandomUtils.nextInt());
    outputStream.writeChar(TEST_CHAR_ID);
    outputStream.writeChars("test");
    outputStream.flush();
}

From source file:com.noxpvp.core.packet.ParticleRunner.java

public void run() {

    if (loc instanceof LivingEntity)
        loc = ((LivingEntity) loc).getEyeLocation().add(0, 1, 0);
    else if (loc instanceof Entity)
        loc = ((Entity) loc).getLocation();
    else if (!(loc instanceof Location))
        throw new IllegalArgumentException("Location must a type of location or entity");

    if ((runs != 0 && i >= runs) || (runs == 0 && i > 0)) {
        safeCancel();/*from w  ww .  j  av  a  2s.  c o m*/
        return;
    }
    i++;

    try {
        CommonPacket commonEffect = new CommonPacket(PacketType.OUT_WORLD_PARTICLES);

        commonEffect.write(PacketType.OUT_WORLD_PARTICLES.effectName, name);
        commonEffect.write(PacketType.OUT_WORLD_PARTICLES.speed, data);
        commonEffect.write(PacketType.OUT_WORLD_PARTICLES.particleCount, amount);

        commonEffect.write(PacketType.OUT_WORLD_PARTICLES.x, (float) ((Location) loc).getX());
        commonEffect.write(PacketType.OUT_WORLD_PARTICLES.y, (float) ((Location) loc).getY());
        commonEffect.write(PacketType.OUT_WORLD_PARTICLES.z, (float) ((Location) loc).getZ());

        if (offSet) {
            commonEffect.write(PacketType.OUT_WORLD_PARTICLES.randomX, RandomUtils.nextFloat());
            commonEffect.write(PacketType.OUT_WORLD_PARTICLES.randomY, RandomUtils.nextFloat());
            commonEffect.write(PacketType.OUT_WORLD_PARTICLES.randomZ, RandomUtils.nextFloat());
        }

        PacketUtil.broadcastPacketNearby((Location) loc, 125, commonEffect);

    } catch (Exception e) {
        e.printStackTrace();
        safeCancel();
        return;
    }
}

From source file:com.epam.catgenome.manager.externaldb.bindings.ExternalDBBindingTest.java

private Object createParam(Class type)
        throws IllegalAccessException, InvocationTargetException, InstantiationException {
    Object param;/*from w w w.  j  av  a 2s . c om*/
    if (type == String.class) {
        param = "test";
    } else if (type == Integer.class || type == Integer.TYPE) {
        param = RandomUtils.nextInt();
    } else if (type == Long.class || type == Long.TYPE) {
        param = RandomUtils.nextLong();
    } else if (type == Float.class || type == Float.TYPE) {
        param = RandomUtils.nextFloat();
    } else if (type == Double.class || type == Double.TYPE) {
        param = RandomUtils.nextDouble();
    } else if (type == Boolean.class || type == Boolean.TYPE) {
        param = RandomUtils.nextBoolean();
    } else if (type == BigInteger.class) {
        param = new BigInteger(TEST_BIGINTEGER);
    } else if (type == List.class) {
        param = new ArrayList<>();
    } else if (type == XMLGregorianCalendar.class) {
        try {
            param = DatatypeFactory.newInstance().newXMLGregorianCalendar();
        } catch (DatatypeConfigurationException e) {
            throw new IllegalArgumentException(e.getMessage(), e);
        }
    } else {
        Constructor[] constructors = type.getConstructors();
        param = constructors[0].newInstance();
    }

    return param;
}

From source file:io.pravega.client.stream.impl.ReaderGroupStateManager.java

/**
 * Add this reader to the reader group so that it is able to acquire segments
 *//*from w ww.jav a  2s.c  o  m*/
void initializeReader(long initialAllocationDelay) {
    AtomicBoolean alreadyAdded = new AtomicBoolean(false);
    sync.updateState(state -> {
        if (state.getSegments(readerId) == null) {
            return Collections.singletonList(new AddReader(readerId));
        } else {
            alreadyAdded.set(true);
            return null;
        }
    });
    if (alreadyAdded.get()) {
        throw new IllegalStateException("The requested reader: " + readerId
                + " cannot be added to the group because it is already in the group. Perhaps close() was not called?");
    }
    long randomDelay = (long) (RandomUtils.nextFloat()
            * Math.min(initialAllocationDelay, sync.getState().getConfig().getGroupRefreshTimeMillis()));
    acquireTimer.reset(Duration.ofMillis(initialAllocationDelay + randomDelay));
}

From source file:org.apache.hadoop.hbase.chaos.monkies.PolicyBasedChaosMonkey.java

/** Selects and returns ceil(ratio * items.length) random items from the given array */
public static <T> List<T> selectRandomItems(T[] items, float ratio) {
    int remaining = (int) Math.ceil(items.length * ratio);

    List<T> selectedItems = new ArrayList<T>(remaining);

    for (int i = 0; i < items.length && remaining > 0; i++) {
        if (RandomUtils.nextFloat() < ((float) remaining / (items.length - i))) {
            selectedItems.add(items[i]);
            remaining--;/*from   w w  w  . j a v a2 s  .  c  om*/
        }
    }

    return selectedItems;
}

From source file:org.apache.horn.core.LayeredNeuralNetwork.java

public int addLayer(int size, boolean isFinalLayer, FloatFunction squashingFunction,
        Class<? extends Neuron> neuronClass, Class<? extends IntermediateOutput> interlayer) {
    Preconditions.checkArgument(size > 0, "Size of layer must be larger than 0.");
    if (!isFinalLayer) {
        if (this.layerSizeList.size() == 0) {
            LOG.info("add input layer: " + size + " neurons");
        } else {//from   ww  w.  j ava 2 s. c  o m
            LOG.info("add hidden layer: " + size + " neurons");
        }
        size += 1;
    }

    this.layerSizeList.add(size);
    int layerIdx = this.layerSizeList.size() - 1;
    if (isFinalLayer) {
        this.finalLayerIdx = layerIdx;
        LOG.info("add output layer: " + size + " neurons");
    }

    // add weights between current layer and previous layer, and input layer has
    // no squashing function
    if (layerIdx > 0) {
        int sizePrevLayer = this.layerSizeList.get(layerIdx - 1);
        // row count equals to size of current size and column count equals to
        // size of previous layer
        int row = isFinalLayer ? size : size - 1;
        int col = sizePrevLayer;
        FloatMatrix weightMatrix = new DenseFloatMatrix(row, col);
        // initialize weights
        weightMatrix.applyToElements(new FloatFunction() {
            @Override
            public float apply(float value) {
                return RandomUtils.nextFloat() - 0.5f;
            }

            @Override
            public float applyDerivative(float value) {
                throw new UnsupportedOperationException("");
            }
        });
        this.weightMatrixList.add(weightMatrix);
        this.prevWeightUpdatesList.add(new DenseFloatMatrix(row, col));
        this.squashingFunctionList.add(squashingFunction);

        this.neuronClassList.add(neuronClass);
    }
    return layerIdx;
}