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

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

Introduction

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

Prototype

public static native int nextInt(int upperBound) ;

Source Link

Document

Returns a random int between 0 (inclusive) and upperBound (exclusive) with roughly equal probability of returning any particular int in this range.

Usage

From source file:com.google.gwt.maeglin89273.shared.test.volcanogame.component.FireBall.java

public FireBall(Spacial space, Point p, int radius) {
    super(new Point(p.getX(), p.getY() - radius), radius * 2, radius * 2);

    this.radius = radius;
    double h = 5 + Random.nextInt(21);
    double s = 80 + Random.nextInt(21);
    double l = 35 + Random.nextInt(16);
    ballColor = CssColor.make("hsl(" + h + "," + s + "%," + l + "%)");
    ballShadowColor = CssColor.make("hsl(" + h + "," + s + "%," + (l + 15) + "%)");
    this.space = space;

    aabb = new PixelAABB(this.position, width, height);

    BodyDef bodyDef = new BodyDef();
    CircleShape shape = new CircleShape();
    FixtureDef fixtureDef = new FixtureDef();
    Vec2 impulse = CoordinateConverter/*w ww.  jav a2 s  .  c om*/
            .vectorPixelsToWorld(new Vector(-30 + 60 * Random.nextDouble(), -(175 + 50 * Random.nextDouble())));

    bodyDef.type = BodyType.DYNAMIC;
    bodyDef.position.set(CoordinateConverter.coordPixelsToWorld(position));

    body = space.getWorld().createBody(bodyDef);
    body.setLinearVelocity(impulse);
    body.applyLinearImpulse(impulse, body.getPosition());
    shape.m_radius = CoordinateConverter.scalerPixelsToWorld(radius);
    fixtureDef.shape = shape;
    fixtureDef.density = 4.3f;
    fixtureDef.restitution = 0.2f;
    fixtureDef.friction = 0.8f;
    body.createFixture(fixtureDef);

}

From source file:com.google.gwt.maeglin89273.shared.test.volcanogame.component.VolcanoWorld.java

public void erupt() {
    add(new FireBall(this,
            new Point(volcano.getLeftCraterPoint().getX() + Random.nextInt(Volcano.CRATER_WIDTH + 1),
                    volcano.getTopY()),//from  w  ww . j a  v a  2 s . c  om
            2 + Random.nextInt(5)));
}

From source file:com.google.gwt.sample.compraventa.client.Compraventa.java

private int obtenerNumeroAleatorio(int max) {
    int retorno = 0;
    retorno = Random.nextInt(max);
    return retorno;
}

From source file:com.google.gwt.sample.guestbook.client.CanvasCustom.java

private static int randomIncrementColourComponent(int colour) {
    int min = (COLOUR_INCREMENT_VECTOR - 1) / 2;
    int rand = Random.nextInt(COLOUR_INCREMENT_VECTOR);
    int vect = rand - min;
    colour = colour + vect;//from   w  ww .  j  a v  a  2s  . c  om
    //       colour = (byte)(   colour + (  Random.nextInt(COLOUR_INCREMENT_VECTOR) - ( (COLOUR_INCREMENT_VECTOR-1) / 2 )  )   );
    if (colour < 0) {
        colour = 0;
    } else if (colour > 255) {
        colour = 255;
    }
    return colour;
}

From source file:com.google.gwt.sample.guestbook.client.CanvasRandom.java

private void randomUpdateCoord() {
    x = x + (Random.nextInt(coordVector) - (COLOUR_INCREMENT_VECTOR / 2));
    if (x < 0) {
        x = 0;//from   www  .j a  v  a2 s  .co m
    } else if (x > WIDTH) {
        x = WIDTH;
    }

    y = y + (Random.nextInt(coordVector) - (COLOUR_INCREMENT_VECTOR / 2));
    if (y < 0) {
        y = 0;
    } else if (y > WIDTH) {
        y = WIDTH;
    }
}

From source file:com.google.gwt.sample.showcase.client.content.cell.ContactDatabase.java

License:Apache License

/**
 * Query the list of friends for the specified contact.
 * /*from w  w  w . j  ava2s  . c  o  m*/
 * @param contact the contact
 * @return the friends of the contact
 */
public Set<ContactInfo> queryFriends(ContactInfo contact) {
    Set<ContactInfo> friends = friendsMap.get(contact.getId());
    if (friends == null) {
        // Assign some random friends.
        friends = new HashSet<ContactInfo>();
        int numContacts = dataProvider.getList().size();
        int friendCount = 2 + Random.nextInt(8);
        for (int i = 0; i < friendCount; i++) {
            friends.add(dataProvider.getList().get(Random.nextInt(numContacts)));
        }
        friendsMap.put(contact.getId(), friends);
    }
    return friends;
}

From source file:com.google.gwt.sample.showcase.client.content.lists.CwTree.java

License:Apache License

/**
 * Create a dynamic tree that will add a random number of children to each
 * node as it is clicked.//from   w  w w.  j  av  a  2s . com
 *
 * @return the new tree
 */
@ShowcaseSource
private Tree createDynamicTree() {
    // Create a new tree
    Tree dynamicTree = new Tree();

    // Add some default tree items
    for (int i = 0; i < 5; i++) {
        TreeItem item = dynamicTree.addItem(constants.cwTreeItem() + " " + i);

        // Temporarily add an item so we can expand this node
        item.addItem("");
    }

    // Add a handler that automatically generates some children
    dynamicTree.addOpenHandler(new OpenHandler<TreeItem>() {
        public void onOpen(OpenEvent<TreeItem> event) {
            TreeItem item = event.getTarget();
            if (item.getChildCount() == 1) {
                // Close the item immediately
                item.setState(false, false);

                // Add a random number of children to the item
                String itemText = item.getText();
                int numChildren = Random.nextInt(5) + 2;
                for (int i = 0; i < numChildren; i++) {
                    TreeItem child = item.addItem(itemText + "." + i);
                    child.addItem("");
                }

                // Remove the temporary item when we finish loading
                item.getChild(0).remove();

                // Reopen the item
                item.setState(true, false);
            }
        }
    });

    // Return the tree
    return dynamicTree;
}

From source file:com.gwtcx.smartgwt.client.util.SecurityUtil.java

License:Open Source License

public static String randomCharString() {
    String r = "";
    for (int i = 0; i < 32; i++) {
        r += (char) ('A' + Random.nextInt(26));
    }//from w w w .  j a v a  2  s  .c  om
    return r;
}

From source file:com.gwttest.client.Demo.java

License:Open Source License

private ChartData get3DBarLineChartData() {
    ChartData cd = new ChartData("Sales by Month 2008",
            "font-size: 14px; font-family: Verdana; text-align: center;");
    cd.setBackgroundColour("#ffffff");

    XAxis xa = new XAxis();
    xa.setLabels("J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D");
    xa.setZDepth3D(8);/*w w  w.ja va2  s . com*/
    xa.setColour("#909090");
    cd.setXAxis(xa);
    YAxis ya = new YAxis();
    ya.setSteps(16);
    ya.setMax(160);
    cd.setYAxis(ya);
    BarChart bchart3 = new BarChart(BarStyle.THREED);
    bchart3.setBarwidth(.5);
    bchart3.setColour("#ff8800");
    for (int t = 0; t < 12; t++) {
        bchart3.addValues(Random.nextInt(50) + 50);
    }
    cd.addElements(bchart3);

    // right axis and line chart
    YAxis yar = new YAxis();
    // yar.setMax(450);
    // yar.setSteps(50);
    yar.setGridColour("#000000");
    cd.setYAxisRight(yar);

    cd.setYLegend(new Text("$M in Sales", "font-size: 11px;"));
    cd.setYRightLegend(new Text("$B in Sales", "font-size: 11px;"));
    cd.setXLegend(new Text("2008/9 Financial Year", "font-size: 11px;"));

    LineChart lc1 = new LineChart();
    lc1.setText("Global Avg");
    lc1.setColour("#000000");
    lc1.setRightAxis(true);
    for (int t = 0; t < 12; t++) {
        lc1.addValues(Random.nextInt(10));
    }
    cd.addElements(lc1);

    return cd;
}

From source file:com.gwttest.client.Demo.java

License:Open Source License

private ChartData getAniPieChartData() {
    ChartData cd = new ChartData("Results", "font-size: 14px; font-family: Verdana; text-align: center;");
    cd.setBackgroundColour("#ffffff");
    PieChart pie = new PieChart();
    pie.setTooltip("#label# $#val#<br>#percent#");
    pie.setAnimateOnShow(true);/*from   w w  w  .  ja  v  a  2s  . c  o  m*/
    pie.setAnimation(new PieChart.PieBounceAnimation(30));
    pie.setGradientFill(false);
    pie.setColours(colours);
    for (int t = 0; t < Random.nextInt(10) + 10; t++) {
        pie.addSlices(new PieChart.Slice(Random.nextDouble() * 1.1 + .5, "" + (t + 1)));
    }
    cd.addElements(pie);
    return cd;
}