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

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

Introduction

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

Prototype

public static native double nextDouble() ;

Source Link

Document

Returns a random double between 0 (inclusive) and 1 (exclusive).

Usage

From source file:ca.nanometrics.gflot.client.example.DecimationExample.java

License:Open Source License

private FakeRpcServiceAsync getRpcService() {
    return new FakeRpcServiceAsync() {

        public void getNewData(final AsyncCallback<DataPoint[]> callback) {
            double up = Random.nextDouble();
            double down = Random.nextDouble();
            callback.onSuccess(new DataPoint[] { new DataPoint(timeCounter++, previous - down),
                    new DataPoint(timeCounter++, previous + up) });
            previous = previous + up;//from w ww .  ja  v a  2  s .  c o  m
        }
    };
}

From source file:ca.nanometrics.gflot.client.example.SlidingWindowExample.java

License:Open Source License

private FakeRpcServiceAsync getRpcService() {
    return new FakeRpcServiceAsync() {
        public void getNewData(final AsyncCallback<DataPoint[]> callback) {
            callback.onSuccess(//  w  w w.j av a 2  s  . co m
                    new DataPoint[] { new DataPoint(Duration.currentTimeMillis(), Random.nextDouble()) });
        }
    };
}

From source file:com.agnie.useradmin.login.client.ui.DeskLoginView.java

License:Open Source License

@UiHandler("loginBtn")
void handleLoginClick(ClickEvent e) {
    clearErrorMessage();//w  w  w.j  av a2 s. co m
    loginBtn.setEnabled(false);

    // Because of some reason when login submit event is fired when user press enter button (event handled through
    // NativePreviewHandler) it fires three times. Which results in multiple calls being made to backend, which in
    // turn results into backend error. Thats where this boolean flag has been introduced to not make a call if it
    // is already been made.
    if (validate() && !authenticationInProgress) {
        authenticationInProgress = true;
        Credential cred = new Credential();
        cred.setUsername(userNameTB.getText());
        String salt = "" + Random.nextDouble();
        cred.setPassword(SHA256.getSHA256Base64(SHA256.getSHA256Base64(passwordTB.getText()) + salt));
        cred.setDomain(LoginQSProcessor.getDomain());
        if (messages.register().equals(loginBtn.getText())) {
            listner.register(cred, salt);
        } else {
            listner.authenticate(cred, salt, checkToRemember.getValue());
        }
    } else {
        loginBtn.setEnabled(true);
    }
}

From source file:com.bigdaz.gwtchart.sample.client.GaugeSample.java

License:Open Source License

public GaugeSample() {
    FlowPanel panel = new FlowPanel();
    gauge = new Gauge(300, 0.2);
    panel.add(gauge);//from w ww .  ja  va  2 s .c  o m
    Button button = new Button("Test me!");
    panel.add(button);

    initWidget(panel);

    button.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            double val = Random.nextDouble();
            gauge.setValue(val);
        }
    });

}

From source file:com.client.hp.hpl.jena.shared.uuid.UUID_V1_Gen.java

License:Apache License

private void setInitialState() {
    Double rand = Random.nextDouble();
    long random = rand.longValue();
    //        long random = LibUUID.makeRandom().nextLong() ;

    node = Bits.unpack(random, 0, 47); // Low 48bits, except groups address bit
    node = Bits.set(node, 47); // Set group address bit

    // Can also set the clock sequence number to increase the randomness.
    // Use up to 13 bits for the clock (actually, it's 14 bits as 
    // strays into the variant).
    // We use less to get a characteristic "-80??-" in the string

    clockSeq = 0;/*  w  ww .j a va 2  s  .  c om*/
    if (CLOCK_BITS != 0)
        clockSeq = (int) Bits.unpack(random, 48, (48 + CLOCK_BITS));
}

From source file:com.client.hp.hpl.jena.shared.uuid.UUID_V4_Gen.java

License:Apache License

public UUID_V4 generateV4() {
    init();/*from   ww w . ja v  a 2 s.co  m*/
    Double mostSigBits = Random.nextDouble();
    Double leastSigBits = Random.nextDouble();

    long convertedMostSigBits = mostSigBits.longValue();
    long convertedLeastSigBits = leastSigBits.longValue();

    convertedMostSigBits = Bits.pack(convertedMostSigBits, versionHere, 12, 16);
    convertedLeastSigBits = Bits.pack(convertedLeastSigBits, variantHere, 62, 64);
    return new UUID_V4(convertedMostSigBits, convertedLeastSigBits);
}

From source file:com.client.hp.hpl.jena.sparql.expr.E_Random.java

License:Apache License

@Override
public NodeValue eval(FunctionEnv env) {
    double d = Random.nextDouble();
    //        double d = RandomLib.random.nextDouble() ;
    return NodeValue.makeDouble(d);
}

From source file:com.google.gwt.example.stockwatcher.client.StockWatcher.java

/**
 * Generate random stock prices.//www.  j  a  va2 s  . c om
 */
private void refreshWatchList() {

    final double MAX_PRICE = 100.0; // $100.00
    final double MAX_PRICE_CHANGE = 0.02; // +/- 2%

    StockPrice[] prices = new StockPrice[stocks.size()];

    for (int i = 0; i < stocks.size(); i++) {
        double price = Random.nextDouble() * MAX_PRICE;
        double change = price * MAX_PRICE_CHANGE * (Random.nextDouble() * 2.0 - 1.0);

        prices[i] = new StockPrice(stocks.get(i), price, change);
    }
    updateTable(prices);
}

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//from  w w w. j  a  va  2 s  . c  o  m
            .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.sample.client.stockwatcher.java

private void refreshWatchList() {
    // Update the price of stocks
    final double MAX_PRICE = 100.0;
    final double MAX_PRICE_CHANGE = 0.02;

    //   Generate random stock prices
    StockPrice[] prices = new StockPrice[stocks.size()];
    for (int i = 0; i < stocks.size(); i++) {
        double price = Random.nextDouble() * MAX_PRICE;
        double diff = price * MAX_PRICE_CHANGE * (Random.nextDouble() * 2.0 - 1.0);

        prices[i] = new StockPrice(stocks.get(i), price, diff);
    }//from   w  w  w  . j a  va  2s  .  c o m

    updateTable(prices);

}