List of usage examples for java.lang Math random
public static double random()
From source file:baggage.BaseTestCase.java
protected void setUp() throws Exception { eventQueue = new LinkedBlockingQueue<String>(); randomInt = (int) (Math.random() * 100000d); randomByte = (byte) (Math.random() * 127d); randomLong = randomLong();//from ww w . j av a 2 s . c o m randomString = randomString(32); }
From source file:com.almende.eve.ggdemo.DAALampAgent.java
public void scheduleLamps() { checkLamps(); schedule("scheduleLamps", null, 1000 + Math.round(Math.random() * 5000)); }
From source file:com.pinterest.terrapin.client.ReplicatedTerrapinClient.java
Pair<TerrapinClient, TerrapinClient> getClientTuple(RequestOptions options) { if (primaryClient == null || secondaryClient == null) { return new ImmutablePair(primaryClient == null ? secondaryClient : primaryClient, null); }//from w w w.j ava 2 s . c o m boolean primaryFirst = Math.random() < 0.5; final TerrapinClient firstClient = options.selectionPolicy == SelectionPolicy.PRIMARY_FIRST ? primaryClient : (primaryFirst ? primaryClient : secondaryClient); final TerrapinClient secondClient = firstClient == primaryClient ? secondaryClient : primaryClient; return new ImmutablePair(firstClient, secondClient); }
From source file:alpha.portal.webapp.controller.BaseControllerTestCase.java
/** * On set up.//from ww w .j av a2 s .c o m */ @Before public void onSetUp() { this.smtpPort = this.smtpPort + (int) (Math.random() * 100); // change the port on the mailSender so it doesn't conflict with an // existing SMTP server on localhost final JavaMailSenderImpl mailSender = (JavaMailSenderImpl) this.applicationContext.getBean("mailSender"); mailSender.setPort(this.getSmtpPort()); mailSender.setHost("localhost"); }
From source file:com.bt.aloha.batchtest.v2.ScenarioRunner.java
private String generateId() { final String randomString = System.currentTimeMillis() + "scenario" + Math.random(); String name = this.scenario.getClass().getSimpleName(); return String.format("%s:%s", name, MessageDigestHelper.generateDigest(randomString)); }
From source file:binky.reportrunner.ui.actions.admin.GetAuditHistoryAction.java
@Override @PreAuthorize("hasRole('ROLE_ADMIN')") public String execute() throws Exception { try {//from w w w.j ava2s . co m logger.trace("module: " + module); this.longestEvents = auditService.getLongestRunningEvents(module, fromDate, toDate); this.latestFailEvents = auditService.getFailedEvents(module, fromDate, toDate); showLongest = true; random = Math.round(Math.random() * 1000000); } catch (Throwable t) { //effing struts eating up exceptions logger.fatal("error in ajax call to get log data", t); if (t instanceof Exception) throw (Exception) t; } return SUCCESS; }
From source file:com.cotrino.knowledgemap.db.Question.java
private void generateQuestion(Page page, List<String> sentences) { int firstSentence = (int) Math.round(Math.random() * (sentences.size() - QUESTION_SENTENCES)); String question = ""; for (int i = firstSentence; i < firstSentence + QUESTION_SENTENCES; i++) { question += sentences.get(i);/*from w w w . ja va 2s. c o m*/ } Matcher matcher = LINK_PATTERN.matcher(question); List<Integer> matchStart = new LinkedList<Integer>(); List<Integer> matchEnd = new LinkedList<Integer>(); List<String> matchLink = new LinkedList<String>(); while (matcher.find()) { String link = matcher.group(1); if (!link.contains(":")) { matchStart.add(matcher.start()); matchEnd.add(matcher.end()); matchLink.add(link); } } if (matchLink.size() > 0) { int linkToBeReplaced = (int) Math.round(Math.random() * (matchLink.size() - 1)); int start = matchStart.get(linkToBeReplaced); int end = matchEnd.get(linkToBeReplaced); String link = matchLink.get(linkToBeReplaced); String[] answers = link.split("\\|"); for (String answer : answers) { this.answers.add(answer); } String placeholder = link.replaceAll("[^ \\|]", "."); if (placeholder.contains("|")) { placeholder = placeholder.split("\\|")[1]; } String text = question.substring(0, start) + "<span class='placeholder'>" + placeholder + "</span>" + question.substring(end); // replace other links of the kind [[A|B]] with A text = text.replaceAll("\\[\\[[^\\]\\|]+\\|", ""); // replace other links of the kind [[A]] with A text = text.replaceAll("\\[\\[", "").replaceAll("\\]\\]", ""); //System.out.println("Question: "+text); this.question = text; this.page = page; } }
From source file:org.hsweb.web.oauth2.service.OAuth2ClientServiceImpl.java
@Override public String insert(OAuth2Client data) { data.setSecret(MD5.encode(UUID.randomUUID().toString() + Math.random())); data.setStatus(1);//from w ww .jav a 2 s . c om return super.insert(data); }
From source file:com.makariev.dynamodb.data.PopulateDataService.java
public String populateUserPreferences(@DsLabel("number of users") int numberOfItems, @DsLabel("name prefix") String namePrefix) { for (int i = 0; i < numberOfItems; i++) { final UserPreference userPreference = new UserPreference(); userPreference.setUserNo((int) (Math.random() * 10000)); userPreference.setFirstName(namePrefix + "-first-" + i); userPreference.setLastName(namePrefix + "-last-" + i); userPreferenceService.save(userPreference); }// w ww. j a va 2 s .c o m return "Created " + numberOfItems + " UserPreference, with prefix=" + namePrefix; }
From source file:com.ideabase.repository.core.service.HashMapStateManagerImpl.java
public String generateRequestStateToken() { final StringBuilder builder = new StringBuilder(); builder.append(mPrefix).append(System.nanoTime()).append(Math.random() * 100).append(mSuffix); return DigestUtils.shaHex(builder.toString()); }