List of usage examples for java.lang Math random
public static double random()
From source file:jungle.controller.PartieController.java
public static String generateString(int length) { StringBuilder pass = new StringBuilder(charLength); for (int x = 0; x < length; x++) { int i = (int) (Math.random() * charLength); pass.append(chars.charAt(i));/*w w w.j a va 2 s . co m*/ } return pass.toString(); }
From source file:Main.java
/** * Positions the specified frame at a random location on the screen while ensuring that the * entire frame is visible (provided that the frame is smaller than the screen). * * @param frame the frame./* w w w . j av a2 s . c o m*/ */ public static void positionFrameRandomly(final Window frame) { positionFrameOnScreen(frame, Math.random(), Math.random()); }
From source file:com.shouwy.series.web.control.application.HomeController.java
private HashMap<Type, Series> getRandSeries(ArrayList<Type> listType, ArrayList<Series> listSeries) { HashMap<Type, Series> mapSeries = new HashMap<Type, Series>(); HashMap<Integer, ArrayList<Series>> mapSeriesByType = Util.mapSeriesByIdType(listSeries); for (Type t : listType) { ArrayList<Series> list = mapSeriesByType.get(t.getId()); Series s = null;// w ww . j a va2 s. c o m if (list != null && !list.isEmpty()) { s = list.get((int) (Math.random() * (list.size()))); } mapSeries.put(t, s); } return mapSeries; }
From source file:org.jfree.chart.demo.DifferenceChartDemo.java
/** * Creates a new demo.// w ww . j a va 2 s .c om * * @param title the frame title. */ public DifferenceChartDemo(final String title) { super(title); final TimeSeries series1 = new TimeSeries("Random 1"); final TimeSeries series2 = new TimeSeries("Random 2"); double value1 = 0.0; double value2 = 0.0; Day day = new Day(); for (int i = 0; i < 200; i++) { value1 = value1 + Math.random() - 0.5; value2 = value2 + Math.random() - 0.5; series1.add(day, value1); series2.add(day, value2); day = (Day) day.next(); } final TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(series1); dataset.addSeries(series2); final JFreeChart chart = createChart(dataset); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); }
From source file:com.yahoo.dba.perf.myperf.springmvc.SigninController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse resp) throws Exception { logger.info("receive url path: " + request.getContextPath() + "," + request.getRequestURI() + ", " + request.getServletPath() + ", parameters: " + request.getQueryString()); boolean failed = false; String username = request.getParameter("name"); if (username != null) { username = username.trim().toLowerCase(); //find the user from the system cache AppUser appUser = this.frameworkContext.getAuth().findUserByName(username); //sign in process boolean authed = this.frameworkContext.getAuth().login(appUser, request); if (authed)//display {//from w w w.j ava 2 s . c o m String view = getLoginSuccessView(); //if admin user, and setup not done yet, send to setup. if (appUser.isAdminUser() && !frameworkContext.getMyperfConfig().isConfigured()) view = this.getSetupView(); logger.info(appUser.getName() + " login, redirect to " + view); return new ModelAndView(new RedirectView(view)); } //if(appUser!=null && appUser.match(request.getParameter("pd")) else { failed = true; } } //if(username!=null) //not authenticated? Try again //TODO add retry count long server_ts = System.currentTimeMillis(); int seed = (int) (Math.random() * Integer.MAX_VALUE); ModelAndView mv = new ModelAndView(getLoginFormView()); mv.addObject("name", username); if (failed) mv.addObject("message", DEFAULT_ERROR); mv.addObject("help_key", "start"); mv.addObject("server_ts", server_ts); mv.addObject("ars", seed);//ars: authentication random seed //add store them in session request.getSession(true).setAttribute(AppUser.SERVER_TS, new Long(server_ts)); request.getSession().setAttribute(AppUser.RANDOM_SEED, new Integer(seed)); return mv; }
From source file:edu.umass.cs.protocoltask.examples.thresholdfetch.MajorityFetchProtocolTask.java
public String refreshKey() { return ((this.myID.toString() + (int) (Math.random() * Integer.MAX_VALUE))); }
From source file:org.jfree.chart.demo.TimePeriodValuesDemo1.java
public XYDataset createDataset1() { TimePeriodValues timeperiodvalues = new TimePeriodValues("Supply"); TimePeriodValues timeperiodvalues1 = new TimePeriodValues("Demand"); Day day = new Day(); for (int i = 0; i < 24; i++) { Minute minute = new Minute(0, new Hour(i, day)); Minute minute1 = new Minute(15, new Hour(i, day)); Minute minute2 = new Minute(30, new Hour(i, day)); Minute minute3 = new Minute(45, new Hour(i, day)); Minute minute4 = new Minute(0, new Hour(i + 1, day)); timeperiodvalues.add(new SimpleTimePeriod(minute.getStart(), minute1.getStart()), Math.random()); timeperiodvalues1.add(new SimpleTimePeriod(minute1.getStart(), minute2.getStart()), Math.random()); timeperiodvalues.add(new SimpleTimePeriod(minute2.getStart(), minute3.getStart()), Math.random()); timeperiodvalues1.add(new SimpleTimePeriod(minute3.getStart(), minute4.getStart()), Math.random()); }//from www . jav a 2s.c om TimePeriodValuesCollection timeperiodvaluescollection = new TimePeriodValuesCollection(); timeperiodvaluescollection.addSeries(timeperiodvalues); timeperiodvaluescollection.addSeries(timeperiodvalues1); return timeperiodvaluescollection; }
From source file:com.ciphertool.sentencebuilder.dao.BasicWordMapDao.java
@Override public Word findRandomWordByLength(Integer length) { ArrayList<Word> wordList = lengthWordMap.get(length); int randomIndex = (int) (Math.random() * wordList.size()); return wordList.get(randomIndex); }
From source file:geogebra.kernel.statistics.AlgoRandomBinomial.java
private int randomBinomialTRS(int n, double p) { if (p > 0.5) return n - randomBinomialTRS(n, 1 - p); if (n * p < 10) return randomBinomial(n, p); double spq = Math.sqrt(n * p * (1 - p)); double b = 1.15 + 2.53 * spq; double a = -0.0873 + 0.0248 * b + 0.01 * p; double c = n * p + 0.5; double v_r = 0.92 - 4.2 / b; double us = 0; double v = 0; while (true) { int k = -1; while (k < 0 || k > n) { double u = Math.random() - 0.5; v = Math.random();/* w w w . ja v a 2 s .c o m*/ us = 0.5 - Math.abs(u); k = (int) Math.floor((2 * a / us + b) * u + c); if (us >= 0.07 && v < v_r) return k; } double alpha = (2.83 + 5.1 / b) * spq; double lpq = Math.log(p / (1 - p)); int m = (int) Math.floor((n + 1) * p); double h = logOfKFactorial(m) + logOfKFactorial((n - m)); v = v * alpha / (a / (us * us) + b); if (v <= h - logOfKFactorial(k) - logOfKFactorial(n - k) + (k - m) * lpq) return k; } }
From source file:com.iisigroup.cap.rule.service.impl.FactorMntServiceImpl.java
@Override public void insertTestCaseInfoData() { BigDecimal[] amount = new BigDecimal[] { new BigDecimal(100000), new BigDecimal(150000), new BigDecimal(900000), new BigDecimal(999999), new BigDecimal(50000), new BigDecimal(330000), new BigDecimal(550000), new BigDecimal(330000), new BigDecimal(150000), new BigDecimal(260000), new BigDecimal(440000), new BigDecimal(100000), new BigDecimal(880000), new BigDecimal(330000), new BigDecimal(150000), new BigDecimal(150000), new BigDecimal(250000), new BigDecimal(440000), new BigDecimal(130000), new BigDecimal(300000) }; Integer[] overDueDay = new Integer[] { 20, 90, 20, 31, 20, 20, 44, 29, 20, 77, 30, 66, 88, 20, 66, 90, 11, 30, 20, 15 };/*ww w.j av a 2s . c om*/ List<CaseInfo> caseList = new ArrayList<CaseInfo>(); Calendar cal = Calendar.getInstance(); int count = 1; for (int j = 1; j <= 20; j++) { for (int i = count; i <= (5000 * j); i++) { CaseInfo cas = new CaseInfo(); cas.setCasNo(StringUtils.leftPad(String.valueOf(i), 20, '0')); int result = (int) (Math.random() * (20 - 1) + 1); cas.setAmount(amount[result]); result = (int) (Math.random() * (20 - 1) + 1); cas.setOverDueDay(overDueDay[result]); cas.setCreator("System"); cas.setCreateTime(new Timestamp(cal.getTimeInMillis())); caseList.add(cas); count++; } caseInfoDao.save(caseList); System.out.println(" case info records :: " + caseList.size()); } }