Example usage for java.util Random Random

List of usage examples for java.util Random Random

Introduction

In this page you can find the example usage for java.util Random Random.

Prototype

public Random(long seed) 

Source Link

Document

Creates a new random number generator using a single long seed.

Usage

From source file:MouseMoveListenerExample.java

public MouseMoveListenerExample() {
    d = new Display();
    s = new Shell(d);

    s.setSize(250, 200);/* www  .j  a v a 2 s.  c  o  m*/

    s.setText("A MouseListener Example");
    final Button b = new Button(s, SWT.PUSH);
    b.setText("Push Me");
    b.setBounds(20, 50, 55, 25);
    s.open();

    b.addMouseMoveListener(new MouseMoveListener() {
        public void mouseMove(MouseEvent e) {
            Random r = new Random(System.currentTimeMillis());
            Point p = s.getSize();
            int newX = r.nextInt(p.y);
            int newY = r.nextInt(p.x);
            b.setBounds(newX - 55, newY - 25, 55, 25);
        }

    });

    while (!s.isDisposed()) {
        if (!d.readAndDispatch())
            d.sleep();
    }
    d.dispose();
}