List of usage examples for org.apache.commons.lang.math RandomUtils nextInt
public static int nextInt(int n)
Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), from the Math.random() sequence.
From source file:com.dianping.wed.cache.redis.util.TestDataUtil.java
public static void main(String[] args) { // ????//from w w w . j av a 2s . c o m //&method=incr¶meterTypes=com.dianping.wed.cache.redis.dto.WeddingRedisKeyDTO¶meters={"category":"justtest","params":["1","2"]} List<String> opList = new ArrayList<String>(opAndKey.keySet()); for (int i = 0; i < 1000; i++) { int index = RandomUtils.nextInt(opList.size()); String op = opList.get(index); String key = opAndKey.get(op); StringBuilder result = new StringBuilder(); int params = buildTestUrl(result, op, key); String fileName = "/Users/Bob/Desktop/data/data-" + params + ".csv"; try { //kuka.txt //kuka.txt FileWriter writer = new FileWriter(fileName, true); writer.write(result.toString()); writer.close(); } catch (IOException e) { e.printStackTrace(); } } System.out.println("done"); }
From source file:io.kodokojo.monitor.Launcher.java
public static void main(String[] args) { Injector propertyInjector = Guice.createInjector(new CommonsPropertyModule(args), new PropertyModule()); MicroServiceConfig microServiceConfig = propertyInjector.getInstance(MicroServiceConfig.class); LOGGER.info("Starting Kodo Kojo {}.", microServiceConfig.name()); Injector commonsServicesInjector = propertyInjector.createChildInjector(new UtilityServiceModule(), new EventBusModule(), new DatabaseModule(), new SecurityModule(), new CommonsHealthCheckModule()); Injector marathonInjector = null;//w ww. ja v a 2 s . c om OrchestratorConfig orchestratorConfig = propertyInjector.getInstance(OrchestratorConfig.class); if (MOCK.equals(orchestratorConfig.orchestrator())) { marathonInjector = commonsServicesInjector.createChildInjector(new AbstractModule() { @Override protected void configure() { // } @Singleton @Provides BrickStateLookup provideBrickStateLookup() { return new BrickStateLookup() { private int cpt = 0; @Override public Set<BrickStateEvent> lookup() { return Collections.singleton(generateBrickStateEvent()); } public BrickStateEvent generateBrickStateEvent() { BrickStateEvent.State[] states = BrickStateEvent.State.values(); int index = RandomUtils.nextInt(states.length); BrickStateEvent.State state = states[index]; return new BrickStateEvent("1234", "build-A", BrickType.CI.name(), "jenkins", state, "1.65Z3.1"); } }; } }); } else { marathonInjector = commonsServicesInjector.createChildInjector(new AbstractModule() { @Override protected void configure() { // } @Singleton @Provides BrickStateLookup provideBrickStateLookup(MarathonConfig marathonConfig, ProjectFetcher projectFectcher, BrickFactory brickFactory, BrickUrlFactory brickUrlFactory, OkHttpClient httpClient) { return new MarathonBrickStateLookup(marathonConfig, projectFectcher, brickFactory, brickUrlFactory, httpClient); } }); } Injector servicesInjector = marathonInjector.createChildInjector(new ServiceModule()); ApplicationLifeCycleManager applicationLifeCycleManager = servicesInjector .getInstance(ApplicationLifeCycleManager.class); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { super.run(); LOGGER.info("Stopping services."); applicationLifeCycleManager.stop(); LOGGER.info("All services stopped."); } }); EventBus eventBus = servicesInjector.getInstance(EventBus.class); eventBus.connect(); // Init repository. BrickStateLookup brickStateLookup = servicesInjector.getInstance(BrickStateLookup.class); BrickStateEventRepository repository = servicesInjector.getInstance(BrickStateEventRepository.class); Set<BrickStateEvent> brickStateEvents = brickStateLookup.lookup(); repository.compareAndUpdate(brickStateEvents); HttpHealthCheckEndpoint httpHealthCheckEndpoint = servicesInjector .getInstance(HttpHealthCheckEndpoint.class); httpHealthCheckEndpoint.start(); ActorSystem actorSystem = servicesInjector.getInstance(ActorSystem.class); ActorRef actorRef = servicesInjector.getInstance(ActorRef.class); actorSystem.scheduler().schedule(Duration.Zero(), Duration.create(1, TimeUnit.MINUTES), actorRef, "Tick", actorSystem.dispatcher(), ActorRef.noSender()); LOGGER.info("Kodo Kojo {} started.", microServiceConfig.name()); }
From source file:edu.uci.ics.crawler4j.weatherCrawler.BasicCrawlController.java
public static void main(String[] args) { String folder = ConfigUtils.getFolder(); String crawlerCount = ConfigUtils.getCrawlerCount(); args = new String[2]; if (StringUtils.isBlank(folder) || StringUtils.isBlank(crawlerCount)) { args[0] = "weather"; args[1] = "10"; System.out.println("No parameters in config.properties ......."); System.out.println("[weather] will be used as rootFolder (it will contain intermediate crawl data)"); System.out.println("[10] will be used as numberOfCralwers (number of concurrent threads)"); } else {//from ww w. j a v a 2 s .co m args[0] = folder; args[1] = crawlerCount; } /* * crawlStorageFolder is a folder where intermediate crawl data is * stored. */ String crawlStorageFolder = args[0]; /* * numberOfCrawlers shows the number of concurrent threads that should * be initiated for crawling. */ int numberOfCrawlers = Integer.parseInt(args[1]); CrawlConfig config = new CrawlConfig(); if (crawlStorageFolder != null && IO.deleteFolderContents(new File(crawlStorageFolder))) System.out.println(""); config.setCrawlStorageFolder(crawlStorageFolder + "/d" + System.currentTimeMillis()); /* * Be polite: Make sure that we don't send more than 1 request per * second (1000 milliseconds between requests). */ config.setPolitenessDelay(1000); config.setConnectionTimeout(1000 * 60); // config1.setPolitenessDelay(1000); /* * You can set the maximum crawl depth here. The default value is -1 for * unlimited depth */ config.setMaxDepthOfCrawling(StringUtils.isBlank(ConfigUtils.getCrawlerDepth()) ? 40 : Integer.valueOf(ConfigUtils.getCrawlerDepth())); // config1.setMaxDepthOfCrawling(0); /* * You can set the maximum number of pages to crawl. The default value * is -1 for unlimited number of pages */ config.setMaxPagesToFetch(100000); // config1.setMaxPagesToFetch(10000); /* * Do you need to set a proxy? If so, you can use: * config.setProxyHost("proxyserver.example.com"); * config.setProxyPort(8080); * * If your proxy also needs authentication: * config.setProxyUsername(username); config.getProxyPassword(password); */ if (ConfigUtils.getValue("useProxy", "false").equalsIgnoreCase("true")) { System.out.println("?============"); List<ProxySetting> proxys = ConfigUtils.getProxyList(); ProxySetting proxy = proxys.get(RandomUtils.nextInt(proxys.size() - 1)); /* test the proxy is alaviable or not */ while (!TestProxy.testProxyAvailable(proxy)) { proxy = proxys.get(RandomUtils.nextInt(proxys.size() - 1)); } System.out.println("??" + proxy.getIp() + ":" + proxy.getPort()); config.setProxyHost(proxy.getIp()); config.setProxyPort(proxy.getPort()); // config.setProxyHost("127.0.0.1"); // config.setProxyPort(8087); } else { System.out.println("??============"); } /* * This config parameter can be used to set your crawl to be resumable * (meaning that you can resume the crawl from a previously * interrupted/crashed crawl). Note: if you enable resuming feature and * want to start a fresh crawl, you need to delete the contents of * rootFolder manually. */ config.setResumableCrawling(false); // config1.setResumableCrawling(false); /* * Instantiate the controller for this crawl. */ PageFetcher pageFetcher = new PageFetcher(config); // PageFetcher pageFetcher1 = new PageFetcher(config1); RobotstxtConfig robotstxtConfig = new RobotstxtConfig(); RobotstxtServer robotstxtServer = new RobotstxtServer(robotstxtConfig, pageFetcher); try { /* * For each crawl, you need to add some seed urls. These are the * first URLs that are fetched and then the crawler starts following * links which are found in these pages */ CrawlController controller = new CrawlController(config, pageFetcher, robotstxtServer); controller.addSeed(StringUtils.isBlank(ConfigUtils.getSeed()) ? "http://www.tianqi.com/chinacity.html" : ConfigUtils.getSeed()); // controller.addSeed("http://www.ics.uci.edu/~lopes/"); // controller.addSeed("http://www.ics.uci.edu/~welling/"); /* * Start the crawl. This is a blocking operation, meaning that your * code will reach the line after this only when crawling is * finished. */ String isDaily = null; isDaily = ConfigUtils.getValue("isDaily", "true"); System.out .println("?=======" + ConfigUtils.getValue("table", "weather_data") + "======="); if (isDaily.equalsIgnoreCase("true")) { System.out.println("???=============="); controller.start(BasicDailyCrawler.class, numberOfCrawlers); } else { System.out.println("???=============="); controller.start(BasicCrawler.class, numberOfCrawlers); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:fr.ritaly.dungeonmaster.audio.SoundSystemV1.java
public static void main(String[] args) throws Exception { // simpleTest(); // testClip(); SoundSystemV1.getInstance().init(new File("c:\\Users\\Francois\\workspace\\Dungeon Master\\sound")); for (int i = 0; i < 10; i++) { switch (RandomUtils.nextInt(4)) { case 0:/*from ww w. j a v a2s . c om*/ SoundSystemV1.getInstance().play(AudioClip.DOOR_BROKEN); break; case 1: SoundSystemV1.getInstance().play(AudioClip.GLOUPS); break; case 2: SoundSystemV1.getInstance().play(AudioClip.FIRE_BALL); break; case 3: SoundSystemV1.getInstance().play(AudioClip.CHAMPION_DIED); break; default: break; } Thread.sleep(300); } while (true) { /* sleep for 1 second. */ try { Thread.sleep(1000); } catch (InterruptedException e) { // Ignore the exception. } SoundSystemV1.getInstance().close(); } }
From source file:com.ms.commons.test.tool.UnitTestTools.java
/** * ??5?/*from w w w. j a v a 2 s . c o m*/ * * @param len * @return */ public static Integer nextInt(Integer len) { if (len == null) { len = 2; } int v = 0; int i = 0; while (i < len) { v *= 10; int x = RandomUtils.nextInt(10); while (x == 0) { x = RandomUtils.nextInt(10); } v += Math.abs(x); i++; } return Math.abs(v); }
From source file:com.github.pmerienne.cf.util.ListUtils.java
public static <T> List<T> randomSubList(List<T> items, int m) { List<T> res = new ArrayList<T>(m); int n = items.size(); for (int i = n - m; i < n; i++) { int pos = RandomUtils.nextInt(i + 1); T item = items.get(pos);//from w w w . j a v a2 s. co m if (res.contains(item)) res.add(items.get(i)); else res.add(item); } return res; }
From source file:com.github.fritaly.svngraph.SvnGraph.java
private static Color randomColor() { return new Color(RandomUtils.nextInt(255), RandomUtils.nextInt(255), RandomUtils.nextInt(255)); }
From source file:fr.ritaly.dungeonmaster.Utils.java
/** * Returns a random value within the specified range [min, max]. * * @param min//from ww w. j av a 2 s .c om * the range's lower bound. Can't be negative. * @param max * the range's upper bound. Can't be negative. * @return a random integer within the specified range. */ public static int random(int min, int max) { Validate.isTrue(min >= 0, String.format("The given min %d must be positive", min)); Validate.isTrue(max >= 0, String.format("The given max %d must be positive", max)); Validate.isTrue(min < max, String.format("The given min %d must be lesser than the max %d", min, max)); return min + RandomUtils.nextInt(max + 1 - min); }
From source file:com.github.pmerienne.cf.util.IndexHelperTest.java
@Test public void should_distribute_uniformely() { // Given//from www.j a v a 2s . c o m long d = 20; int indexPerBlock = RandomUtils.nextInt(100); // When Map<Long, Integer> distribution = new HashMap<>(); for (long i = 0; i < d * indexPerBlock; i++) { long block = IndexHelper.toBlockIndex(i, d); int count = distribution.containsKey(block) ? distribution.get(block) : 0; distribution.put(block, count + 1); } // Then Assertions.assertThat(distribution.values()).containsOnly(indexPerBlock); }
From source file:fr.ritaly.dungeonmaster.Sector.java
/** * Returns a random sector./* w w w. jav a 2 s. c om*/ * * @return a sector. Never returns null. */ public static Sector random() { return Sector.values()[RandomUtils.nextInt(COUNT)]; }