List of usage examples for com.google.gwt.user.client Random nextInt
public static native int nextInt(int upperBound) ;
int
between 0 (inclusive) and upperBound
(exclusive) with roughly equal probability of returning any particular int
in this range. From source file:at.ait.dme.yuma.client.map.tagcloud.TagCloudQuadrant.java
License:EUPL
public void addTag(SemanticTag tag, int fontsize, String hiliteColor) { boolean firstTagInLine = false; RaphaelTag rTag = new RaphaelTag(tag, originX + offsetX, originY + offsetY, fontsize, hiliteColor, hAlign, vAlign, paper, listener);//w ww. j a v a 2 s .co m if (offsetX == 0) { lineHeight = rTag.getHeight() + TagCloud.TAG_BUFFER_Y; // First tag in line firstTagInLine = true; } offsetX += dirX * (rTag.getWidth() + TagCloud.TAG_BUFFER_X); if ((!firstTagInLine) && (Math.abs(offsetX) > maxWidth)) { rTag.translate(dirX * (rTag.getWidth() + TagCloud.TAG_BUFFER_X) - offsetX, lineHeight * dirY); offsetX = dirX * (rTag.getWidth() + TagCloud.TAG_BUFFER_X); offsetY += dirY * lineHeight; lineHeight = rTag.getHeight() + TagCloud.TAG_BUFFER_Y; } rTag.fade(1, TagCloud.FADE_IN_TIME, Random.nextInt(20) * 100); tagList.add(rTag); }
From source file:at.ait.dme.yuma.client.map.tagcloud.TagCloudQuadrant.java
License:EUPL
public void fadeoutAndClear(final AnimationEventHandler handler) { // Reset tag cloud properties offsetX = 0;//from w w w . ja va2s. c o m offsetY = 0; lineHeight = 0; // Fade out all tags on the canvas final int limit = tagList.size(); if (limit == 0 && handler != null) handler.onAnimationComplete(); for (RaphaelTag tag : tagList) { tag.fade(0, TagCloud.FADE_OUT_TIME, Random.nextInt(20) * 50, new AnimationEventHandler() { @Override public void onAnimationComplete() { fadeCtr++; if (fadeCtr == limit) { fadeCtr = 0; if (handler != null) handler.onAnimationComplete(); } } }); } // Clear the tag list tagList.clear(); }
From source file:be.dramaix.ai.slidingpuzzle.shared.State.java
License:Apache License
public static State createRandom(int dimension) { State s = new State(getGoalState(dimension).getAllCells()); Action old = null;/* w w w. ja v a 2 s. com*/ for (int i = 0; i < 500; i++) { List<Action> actions = s.getPossibleActions(); // pick an action randomly int index = Random.nextInt(actions.size()); Action a = actions.get(index); if (old != null && old.isInverse(a)) { if (index == 0) { index = 1; } else { index--; } a = actions.get(index); } s = a.applyTo(s); old = a; } return s; }
From source file:ca.farez.sortsomething.client.Sortsomething.java
License:Apache License
private String generateRandomQuiz(int size) { String quiz = ""; String block = ""; String callnumber = ""; int numBlocks; // 3, 4 or 5 including year int cnInt; // Range 1 - 9 no decimals for now int numInts; // 1, 2, 3 or 4 integers int numAlpha; // 1, 2 or 3 alphabet letters char[] chars = "abcdefghijklmnopqrstuvwxyz".toCharArray(); // For every call number for (int i = 0; i < size; i++) { // Make 2,3, or 4 line/blocks numBlocks = Random.nextInt(3) + 2; // For every block for (int j = 0; j < numBlocks; j++) { numInts = Random.nextInt(4) + 1; cnInt = Random.nextInt(10); numAlpha = Random.nextInt(3) + 1; block = ""; for (int k = 0; k < numAlpha; k++) { block += chars[Random.nextInt(chars.length)]; }//from ww w.j a v a 2 s . co m block = block.toUpperCase(); for (int m = 0; m < numInts; m++) { block += Integer.toString(cnInt); cnInt = Random.nextInt(10); } if (j < numBlocks - 1) block += " "; callnumber += block; } // Append a "year" to the call number Date today = new Date(); String year = DateTimeFormat.getFormat("d-M-yyyy").format(new Date()).split("-")[2]; callnumber = callnumber + " " + Integer.toString(Random.nextInt(Integer.parseInt(year) + 1)); // Append it to quiz quiz = callnumber + lineSeparator; } return quiz; }
From source file:ch.unifr.pai.ice.client.clickblobs.Blob.java
License:Apache License
private int randomNum(int upperBond) { return Random.nextInt(upperBond); }
From source file:ch.unifr.pai.ice.client.clickblobs.ClickBlobs1user.java
License:Apache License
private int randomNum(int upperBond) { return Random.nextInt(upperBond); }
From source file:ch.unifr.pai.ice.client.clickblobs.ClickBlobs2users.java
License:Apache License
/** * Generate a random number with an upper boundary * /*w w w .ja v a 2 s.c o m*/ * @param upperBond * @return int */ private int randomNum(int lowerBond, int upperBond) { int num = Random.nextInt(upperBond); while (num <= lowerBond) { num = Random.nextInt(upperBond); } return num; }
From source file:ch.unifr.pai.ice.client.dragNdrop.DnD1userGeneric.java
License:Apache License
/** * Generate a random number with an upper boundary * //from ww w . j a va2 s .co m * @param upperBond * @return int */ private int randomNum(int upperBond) { return Random.nextInt(upperBond); }
From source file:ch.unifr.pai.twice.utils.cursorSimulator.client.examples.CursorSimulation.java
License:Apache License
/** * Adds a cursor that follows a random path on the screen and start the movement immediately. *//*from w w w . j ava2 s .c o m*/ public static void addSimulatedCursor() { RandomCursor c = new RandomCursor(counter++, 1500 + Random.nextInt(1000), 300, 300); RootPanel.get().add(c); c.start(); }
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.//from www . j a va 2 s . c om */ 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); }