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:de.spartusch.nasfvi.client.MainWidget.java
License:Apache License
/** * Selects some examples randomly and displays them. *///from w ww . j a va 2s .c om private void setExamples() { StringBuilder sb = new StringBuilder(); for (int i = 0; i < 5; i++) { int index = Random.nextInt(examples.length); sb.append("<li>").append(examples[index]).append("</li>"); } exampleItems.setHTML(sb.toString()); }
From source file:edu.ycp.cs.netcoder.client.affect.AffectWidget.java
License:Open Source License
private Emotion[] randomizeEmotions() { // GWT (as of version 2.2) does not have Collections.shuffle, sigh Emotion[] orig = Emotion.values();//w ww . j a v a2 s. c o m Emotion[] result = new Emotion[orig.length]; for (int i = 0; i < orig.length; i++) { result[i] = orig[i]; } for (int i = 0; i < result.length; i++) { int swap = Random.nextInt(result.length); Emotion tmp = result[i]; result[i] = result[swap]; result[swap] = tmp; } return result; }
From source file:eml.studio.client.controller.DiagramController.java
License:Open Source License
/** * Place a new widget to paint panel/*from ww w.j a v a 2 s. c om*/ * * @param widget */ public void addWidget(final BaseWidget widget) { int h = this.scrollPanel.getOffsetHeight(); int w = this.scrollPanel.getOffsetWidth(); int offsetx = this.scrollPanel.getHorizontalScrollPosition(); int offsety = this.scrollPanel.getVerticalScrollPosition(); int x = offsetx + 4 * w / 9 + Random.nextInt(100); int y = offsety + 2 * h / 7 + Random.nextInt(100); addWidget(widget, x, y); }
From source file:fr.drop.shared.ProjectDatabase.java
License:Apache License
/** * Query the list of friends for the specified contact. * /*from ww w . j a va 2s . co m*/ * @param contact the contact * @return the friends of the contact */ public Set<DropUser> queryFriends(DropUser contact) { Set<DropUser> friends = friendsMap.get(contact.getId()); if (friends == null) { // Assign some random friends. friends = new HashSet<DropUser>(); 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:fr.drop.shared.ProjectDatabase.java
License:Apache License
/** * Create a new random {@link DropUser}. * // w w w . ja v a 2 s . com * @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}. * //from w w w. j av a 2 s. c o m * @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; }
From source file:fr.insalyon.creatis.vip.application.client.ApplicationModule.java
License:Open Source License
@Override public void userRemoved(User user) { final AsyncCallback<Void> callback = new AsyncCallback<Void>() { @Override/*from w w w . ja v a 2 s. c o m*/ public void onFailure(Throwable caught) { Layout.getInstance() .setWarningMessage("Unable to anonymize user data:<br />" + caught.getMessage()); } @Override public void onSuccess(Void result) { } }; WorkflowService.Util.getInstance().updateUser(user.getFullName(), "User-" + Random.nextInt(100000), callback); }
From source file:gov.nih.nci.ncicb.tcgaportal.level4.gwt.anomalysearch.client.results.ModeController.java
private String getExportFileName() { String diskFileName = String.valueOf(Random.nextInt(1000) + System.currentTimeMillis()); diskFileName += ".txt"; return diskFileName; }
From source file:gwt.g2d.tetris.client.Piece.java
License:Apache License
/** * Creates a random tetris piece. */ public Piece() { pieceDefinition = PieceDefinition.randomPieceDefinition(); rotation = Random.nextInt(PIECE_SIZE); }
From source file:gwt.g2d.tetris.client.PieceDefinition.java
License:Apache License
/** * Gets a random piece definition. */ public static PieceDefinition randomPieceDefinition() { return PIECES[Random.nextInt(PIECES.length)]; }