Example usage for com.google.gwt.user.client Random nextBoolean

List of usage examples for com.google.gwt.user.client Random nextBoolean

Introduction

In this page you can find the example usage for com.google.gwt.user.client Random nextBoolean.

Prototype

public static native boolean nextBoolean() ;

Source Link

Document

Returns true or false with roughly equal probability.

Usage

From source file:ch.unifr.pai.twice.utils.cursorSimulator.client.RandomCursor.java

License:Apache License

/**
 * Move the mouse pointer randomly (the mouse pointer does not move every time but decides on if to move within this interval depending on a random boolean
 * choice as well./*w ww .j a  v  a2  s .  c o m*/
 */
private void move() {
    int newX;
    int newY;
    if (Random.nextBoolean()) {
        newX = Random.nextInt(Window.getClientWidth() - RandomCursor.this.getOffsetWidth());
        newY = Random.nextInt(Window.getClientHeight() - RandomCursor.this.getOffsetHeight());
    } else {
        newX = RandomCursor.this.getAbsoluteLeft();
        newY = RandomCursor.this.getAbsoluteTop();
    }
    move(newX, newY, interval, moveCallback);
}

From source file:com.arcbees.gquery.tooltip.client.contactcell.ContactDatabase.java

License:Apache License

@SuppressWarnings("deprecation")
private ContactInfo createContactInfo() {
    // set all created contact in OTHERS category
    ContactInfo contact = new ContactInfo();
    contact.setLastName(nextValue(LAST_NAMES));
    if (Random.nextBoolean()) {
        // Male.//from   w w  w  . ja v a  2s .  c om
        contact.setFirstName(nextValue(MALE_FIRST_NAMES));
    } else {
        // Female.
        contact.setFirstName(nextValue(FEMALE_FIRST_NAMES));
    }

    // Create a birthday between 20-80 years ago.
    int year = (new Date()).getYear() - 21 - Random.nextInt(61);
    contact.setBirthday(new Date(year, Random.nextInt(12), 1 + Random.nextInt(31)));

    // Create an address.
    int addrNum = 1 + Random.nextInt(999);
    String addrStreet = nextValue(STREET_NAMES);
    String addrSuffix = nextValue(STREET_SUFFIX);
    contact.setAddress(addrNum + " " + addrStreet + " " + addrSuffix);
    return contact;
}

From source file:com.freedomotic.clients.client.widgets.ContactDatabase.java

License:Apache License

/**
 * Create a new random {@link ContactInfo}.
 *
 * @return the new {@link ContactInfo}./*from w  w  w.jav a  2  s .  com*/
 */
@SuppressWarnings("deprecation")
private ContactInfo createContactInfo() {
    ContactInfo contact = new ContactInfo(nextValue(categories));
    contact.setLastName(nextValue(LAST_NAMES));
    if (Random.nextBoolean()) {
        // Male.
        contact.setFirstName(nextValue(MALE_FIRST_NAMES));
    } else {
        // Female.
        contact.setFirstName(nextValue(FEMALE_FIRST_NAMES));
    }

    // Create a birthday between 20-80 years ago.
    int year = (new Date()).getYear() - 21 - Random.nextInt(61);
    contact.setBirthday(new Date(year, Random.nextInt(12), 1 + Random.nextInt(31)));

    // Create an address.
    int addrNum = 1 + Random.nextInt(999);
    String addrStreet = nextValue(STREET_NAMES);
    String addrSuffix = nextValue(STREET_SUFFIX);
    contact.setAddress(addrNum + " " + addrStreet + " " + addrSuffix);
    return contact;
}

From source file:com.sciencegadgets.client.algebra.ConstantRandomizer.java

License:Open Source License

private static BigDecimal getRandomNumber(String varRandomness) {

    // negative_lowerBound_upperBound_decimal place
    String[] specs = varRandomness.split(RandomSpecPanel.RANDOMNESS_DELIMITER);
    try {//w  ww .  j a  va  2  s  .  c  o m
        String negativity = specs[0];
        double lowerBound = Double.parseDouble(specs[1]);
        double upperBound = Double.parseDouble(specs[2]);
        int decPlace = Integer.parseInt(specs[3]);

        // Randomize within bounds
        double randomNumber = (Math.random() * (upperBound - lowerBound)) + lowerBound;

        // Make negative
        if (RandomSpecPanel.ALWAYS.equals(negativity)
                || RandomSpecPanel.SOMETIMES.equals(negativity) && Random.nextBoolean()) {
            randomNumber *= -1;
        }

        BigDecimal randomBigD = new BigDecimal(randomNumber);
        randomBigD = randomBigD.setScale(decPlace, BigDecimal.ROUND_DOWN);

        return randomBigD;

    } catch (NumberFormatException | ArithmeticException e) {
        e.printStackTrace();
        return new BigDecimal((Math.random() * 10) + 1);
    }
}

From source file:com.sciencegadgets.client.algebra.EquationGenerator.java

License:Open Source License

private static void GERERATE_SIDE(EquationNode side, //
        LinkedHashMap<TypeSGET, Integer> expressions, //
        boolean mustBeWholeAnswer, //
        boolean mustBePositives, //
        int minAdd, //
        int minMultiply, //
        int minFraction, //
        int minExp, //
        int maxAdd, //
        int maxMultiply, //
        int maxFraction, //
        int maxExp) {

    HashSet<TypeSGET> toRemove = new HashSet<TypeSGET>();

    for (Entry<TypeSGET, Integer> entry : expressions.entrySet()) {
        if (entry.getValue() == 0) {
            toRemove.add(entry.getKey());
        }/*from w ww .j av a2s  . c  o m*/
    }
    for (TypeSGET type : toRemove) {
        expressions.remove(type);
    }

    while (!expressions.isEmpty()) {
        int index = Random.nextInt(expressions.size());
        TypeSGET[] array = expressions.keySet().toArray(new TypeSGET[expressions.size()]);
        TypeSGET type = array[index];

        switch (type) {
        case Sum:
            int valueAdd = Random.nextInt(maxAdd - minAdd) + minAdd;
            if (!mustBePositives && Random.nextBoolean()) {
                valueAdd *= -1;
            }
            side = ADD_SUB(side, valueAdd, mustBePositives);
            break;
        case Term:
            int valueMultiply = Random.nextInt(maxMultiply - minMultiply) + minMultiply;
            if (!mustBePositives && Random.nextBoolean()) {
                valueMultiply *= -1;
            }
            side = MULTIPLY(side, valueMultiply);
            break;
        case Fraction:
            side = FRACTION(side, mustBeWholeAnswer, maxMultiply, minFraction, maxFraction);
            break;
        case Exponential:
            side = EXP(side, minExp, maxExp);
            break;
        case Trig:
            side = TRIG(side);
            break;
        case Log:
            side = LOG(side);
            break;
        }

        int expressionCount = expressions.get(type) - 1;
        if (expressionCount > 0) {
            expressions.put(type, expressionCount);
        } else {
            expressions.remove(type);
        }
    }
}

From source file:com.sciencegadgets.client.algebra.EquationGenerator.java

License:Open Source License

private static EquationNode FRACTION(EquationNode node, boolean mustBeWholeAnswer, int maxMultiply,
        int minFraction, int maxFraction) {

    int smaller = Random.nextInt(maxMultiply) + 1 + minFraction;
    int bigger = smaller * Random.nextInt(maxFraction) + 2;

    int numeratorValue, denominatorValue;
    if (!mustBeWholeAnswer && Random.nextBoolean()) {
        numeratorValue = smaller;/*from www. j  av a 2  s  .  co  m*/
        denominatorValue = bigger;
    } else {
        numeratorValue = bigger;
        denominatorValue = smaller;
    }

    EquationNode fraction;
    if (TypeSGET.Fraction.equals(node.getType())) {
        fraction = node;
        MULTIPLY(fraction.getChildAt(0), numeratorValue);
        MULTIPLY(fraction.getChildAt(1), denominatorValue);
    } else {
        node = MULTIPLY(node, numeratorValue);
        fraction = node.encase(TypeSGET.Fraction);
        fraction.append(TypeSGET.Number, denominatorValue + "");
    }
    return fraction;
}

From source file:com.sciencegadgets.client.algebra.EquationGenerator.java

License:Open Source License

private static EquationNode ADD_SUB(EquationNode node, int value, boolean mustBePositives) {
    Operator op = !mustBePositives && Random.nextBoolean() ? Operator.MINUS : Operator.PLUS;

    node = node.encase(TypeSGET.Sum);//www .j  a va  2s . c  om
    node.append(TypeSGET.Operation, op.getSign());
    node.append(TypeSGET.Number, value + "");
    return node;
}

From source file:com.thezukunft.wave.connectormock.WaveMock.java

License:Open Source License

public void initRandomParticipants() {

    // init some viewer and add it
    ParticipantMock p = JavaScriptObject.createObject().cast();
    p.setupMock();/*  w ww. j av a2 s. com*/
    p.setDisplayName("Robin the Simple");
    p.setId("1a");
    p.setThumbnailUrl(GWT.getModuleBaseURL() + "robin.jpg");
    participants.push(p);

    // init some host and add it 50% of the time
    ParticipantMock h = JavaScriptObject.createObject().cast();
    h.setupMock();
    h.setDisplayName("Batman the Host");
    h.setId("2b");
    h.setThumbnailUrl(GWT.getModuleBaseURL() + "/batman.jpg");
    participants.push(h);

    viewer = Random.nextBoolean() ? p : h;
    host = Random.nextBoolean() ? h : p;

    eventBus.fireEvent(new ParticipantUpdateEvent(this));
}

From source file:fr.drop.shared.ProjectDatabase.java

License:Apache License

/**
 * Create a new random {@link DropUser}.
 * //from  w  w  w  . j  ava2  s .  c o m
 * @return the new {@link DropUser}.
 */
@SuppressWarnings("deprecation")
private DropUser createContactInfo() {
    DropUser contact = new DropUser(nextValue(categories));
    contact.setDescription(nextValue(LAST_NAMES));
    if (Random.nextBoolean()) {
        // Male.
        contact.setProjectName(nextValue(MALE_FIRST_NAMES));
    } else {
        // Female.
        contact.setProjectName(nextValue(FEMALE_FIRST_NAMES));
    }

    // Create a birthday between 20-80 years ago.
    int year = (new Date()).getYear() - 21 - Random.nextInt(61);
    contact.setBirthday(new Date(year, Random.nextInt(12), 1 + Random.nextInt(31)));

    // Create an address.
    int addrNum = 1 + Random.nextInt(999);
    String addrStreet = nextValue(STREET_NAMES);
    String addrSuffix = nextValue(STREET_SUFFIX);
    contact.setAddress(addrNum + " " + addrStreet + " " + addrSuffix);
    return contact;
}

From source file:fr.drop.shared.UserDatabase.java

License:Apache License

/**
 * Create a new random {@link DropUser}.
 * // www  .  ja  v a 2 s  .  c  om
 * @return the new {@link DropUser}.
 */
@SuppressWarnings("deprecation")
private DropUser createContactInfo() {
    DropUser contact = new DropUser();
    contact.setLastName(nextValue(LAST_NAMES));
    if (Random.nextBoolean()) {
        // Male.
        contact.setFirstName(nextValue(MALE_FIRST_NAMES));
    } else {
        // Female.
        contact.setFirstName(nextValue(FEMALE_FIRST_NAMES));
    }

    // Create a birthday between 20-80 years ago.
    int year = (new Date()).getYear() - 21 - Random.nextInt(61);
    contact.setBirthday(new Date(year, Random.nextInt(12), 1 + Random.nextInt(31)));

    // Create an address.
    int addrNum = 1 + Random.nextInt(999);
    String addrStreet = nextValue(STREET_NAMES);
    String addrSuffix = nextValue(STREET_SUFFIX);
    contact.setAddress(addrNum + " " + addrStreet + " " + addrSuffix);
    return contact;
}