當前位置: 首頁>>代碼示例>>Java>>正文


Java RandomUtils.nextInt方法代碼示例

本文整理匯總了Java中org.apache.commons.lang3.RandomUtils.nextInt方法的典型用法代碼示例。如果您正苦於以下問題:Java RandomUtils.nextInt方法的具體用法?Java RandomUtils.nextInt怎麽用?Java RandomUtils.nextInt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.lang3.RandomUtils的用法示例。


在下文中一共展示了RandomUtils.nextInt方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: get

import org.apache.commons.lang3.RandomUtils; //導入方法依賴的package包/類
@Test
public void get() {
    //String content = HttpClientUtil.get("https://github.com/mumucommon/mumu-core");
    //System.out.println(content);
    int i = RandomUtils.nextInt(0, 2);
    System.out.println(i);
}
 
開發者ID:mumucommon,項目名稱:mumu-core,代碼行數:8,代碼來源:HttpClientUtilTest.java

示例2: testCreateAndGet

import org.apache.commons.lang3.RandomUtils; //導入方法依賴的package包/類
@Test
public void testCreateAndGet(){
	PayOrder.Builder builder = PayOrder.newBuilder();
	long uid = System.currentTimeMillis();
	long id = (uid * 10 + 1);
	builder.setId(id);
	builder.setAppId("myapp");
	builder.setKey(id);
	builder.setCreateTime(new Date().getTime());
	builder.setCurrentKey(19283745);
	builder.setDestPayType(1982);
	builder.setSubId(uid);
	Calendar expireTime = Calendar.getInstance();
	expireTime.add(Calendar.HOUR, 1);
	builder.setExpireTime(expireTime.getTime().getTime());
	int fee = RandomUtils.nextInt(1, 1000000);
	builder.setFee(fee);
	builder.setFeeReal(RandomUtils.nextInt(1, fee));
	builder.setFeeUnit(FeeUnit.CNY_VALUE);
	builder.setNotifyUrl("http://localhost/notify");
	builder.setReturnUrl("http://localhost/returnUrl");
	builder.setOrderDetail("OrderDetail");
	builder.setOrderId(UUID.randomUUID().toString());
	repository.create(builder.build());
	PayOrder order = repository.get(id);
	Assert.assertEquals(order.getId(), id);
	
}
 
開發者ID:jigsaw-projects,項目名稱:jigsaw-payment,代碼行數:29,代碼來源:TestPayOrderRepository.java

示例3: getRandomIdWithException

import org.apache.commons.lang3.RandomUtils; //導入方法依賴的package包/類
/**
 * Get a random integer except the one(s) in the the ex
 * @param vType vertex label
 * @param ex unsorted list of unique numbers to exclude
 * @return an integer not in the exclude list or -1 if not found
 */
public int getRandomIdWithException(String vType, List<Integer> ex) {
    int start = idBean.getMinId(vType);
    int end = idBean.getMaxId(vType);
    boolean found = false;
    int rnd = -1;
    if (ex.size() > (end - start))
        return rnd;
    while (!found) {
        rnd = RandomUtils.nextInt(start, end + 1);
        if (false == ex.contains(rnd)) {
            found = true;
        }
    }
    return rnd;
}
 
開發者ID:IBM,項目名稱:janusgraph-utils,代碼行數:22,代碼來源:IdStore.java

示例4: chaosMonkey

import org.apache.commons.lang3.RandomUtils; //導入方法依賴的package包/類
private void chaosMonkey() {
    if (chaosMonkey.get()) {
        // Trouble?
        int troubleRand = RandomUtils.nextInt(0, 10);
        int exceptionRand = RandomUtils.nextInt(0, 10);

        if (troubleRand > chaosMonkeyLevel.get()) {
            LOGGER.debug("Chaos Monkey - generates trouble");
            // Timeout or Exception?
            if (exceptionRand < 7) {
                LOGGER.debug("Chaos Monkey - timeout");
                // Timeout
                generateTimeout();
            } else {
                LOGGER.debug("Chaos Monkey - exception");
                // Exception
                throw new RuntimeException("Chaos Monkey - RuntimeException");
            }
        }
    }
}
 
開發者ID:MrBW,項目名稱:resilient-transport-service,代碼行數:22,代碼來源:ChaosMonkey.java

示例5: createPacket

import org.apache.commons.lang3.RandomUtils; //導入方法依賴的package包/類
/**
 * @return
 */
private ICMPPacket createPacket(final InetAddress destIp, final short hop) {
	final ICMPPacket packet = new ICMPPacket();
	packet.type = ICMPPacket.ICMP_ECHO;
	packet.seq = 100;
	packet.id = (short) RandomUtils.nextInt(0, 100);
	packet.setIPv4Parameter(0, false, false, false, 0, false, false, false, 0, 0, 0, IPPacket.IPPROTO_ICMP, _deviceIp, destIp);
	final String data = "ovtr";
	packet.data = data.getBytes();
	final EthernetPacket ether = new EthernetPacket();
	ether.frametype = EthernetPacket.ETHERTYPE_IP;
	ether.src_mac = _device.mac_address;
	ether.dst_mac = _gatewayMac;
	packet.datalink = ether;
	packet.hop_limit = hop;
	return packet;
}
 
開發者ID:leolewis,項目名稱:openvisualtraceroute,代碼行數:20,代碼來源:JpcapTraceRoute.java

示例6: test

import org.apache.commons.lang3.RandomUtils; //導入方法依賴的package包/類
@GetMapping("/test")
Map<String, Object> test(
	@RequestParam(required = false, defaultValue = "") String id) {

	result.put("timestamp", LocalDateTime.now());

	int randomInt = RandomUtils.nextInt(0, 100);
	if (StringUtils.hasText(id)) {
		customerCommandService.handle(new ChangeCustomerEmailCommand(id, "admin2", "zmieniony-Pablo" + randomInt));
		result.put(id, customerRepository.get(new RootAggregateId(id)).toString());
	}
	else {
		int randomInt2 = RandomUtils.nextInt(0, 10);
		String customerId = UUID.randomUUID().toString();
		customerCommandService
			.handle(new CreateCustomerCommand(customerId, "admin", "Pablo" + randomInt2, "Picasso" + randomInt2, "pablo" + randomInt2 + "@picasso.pl", "12121234563"));
		result.put(customerId, customerRepository.get(new RootAggregateId(customerId)).toString());
	}

	return result;
}
 
開發者ID:bilu,項目名稱:yaess,代碼行數:22,代碼來源:TestController.java

示例7: generateLocations

import org.apache.commons.lang3.RandomUtils; //導入方法依賴的package包/類
private Set<Location> generateLocations(LocationSpec locationSpec) {
    Set<Location> result = new HashSet<>();

    List<Location> originalLocationStubs = getLocationStubs();
    val locationStubs = originalLocationStubs.stream().filter(l -> RandomUtils.nextBoolean()).collect(toList());
    if (isEmpty(locationStubs)) {
        int randomLocationPosition = RandomUtils.nextInt(0, originalLocationStubs.size() - 1);
        Location randomLocationStub = originalLocationStubs.get(randomLocationPosition);
        locationStubs.add(randomLocationStub);
    }

    int locationsLimit = min(locationSpec.getMax(), locationStubs.size());
    int countLocations = RandomUtils.nextInt(1, locationsLimit);

    IntStream.range(0, countLocations).forEachOrdered(i -> {
        Location locationStub = locationStubs.get(i);
        updateLocationStubToLocation(locationSpec, locationStub);
        result.add(locationStub);
    });

    return result;
}
 
開發者ID:xm-online,項目名稱:xm-ms-entity,代碼行數:23,代碼來源:XmEntityGeneratorService.java

示例8: updateLocationStubToLocation

import org.apache.commons.lang3.RandomUtils; //導入方法依賴的package包/類
private void updateLocationStubToLocation(LocationSpec locationSpec, Location locationStub) {

        locationStub.typeKey(locationSpec.getKey()).name(randomAnyString() + " locations");

        if (RandomUtils.nextInt(1, 10) < 5) {
            locationStub.addressLine1(null).addressLine2(null).city(null).region(null);
        } else if (RandomUtils.nextInt(1, 10) > 5) {
            locationStub.latitude(null).longitude(null);
        }
        // TODO: change this when Country DB entity will be removed
        locationStub.setCountryKey(null);
    }
 
開發者ID:xm-online,項目名稱:xm-ms-entity,代碼行數:13,代碼來源:XmEntityGeneratorService.java

示例9: randomWord

import org.apache.commons.lang3.RandomUtils; //導入方法依賴的package包/類
private DrawWordInfo randomWord() {
    long count = mapper.countByExample(null);
    int select = RandomUtils.nextInt(0, (int) count);
    DrawWordExample ex = new DrawWordExample();
    ex.createCriteria().andIdGreaterThan(select);
    DrawWord drawWord = mapper.selectOneByExample(ex);
    DrawWordInfo info = new DrawWordInfo();
    info.setWord(drawWord.getWord());
    info.setWordType(drawWord.getWordTip());
    info.setWordCount(drawWord.getWord().length());
    return info;
}
 
開發者ID:csdbianhua,項目名稱:telemarket-skittle-alley,代碼行數:13,代碼來源:DrawGuess.java

示例10: generateTimeout

import org.apache.commons.lang3.RandomUtils; //導入方法依賴的package包/類
/***
 * Generates a timeout exception
 */
private void generateTimeout() {
    int timeout = RandomUtils.nextInt(timeoutRangeStart.get(), timeoutRangeEnd.get());

    try {
        Thread.sleep(timeout);
    } catch (InterruptedException e) {
        // do nothing, hystrix tries to interrupt
    }
}
 
開發者ID:MrBW,項目名稱:spring-aop-chaos-monkey,代碼行數:13,代碼來源:ChaosMonkey.java

示例11: sendEmail

import org.apache.commons.lang3.RandomUtils; //導入方法依賴的package包/類
/**
 * 發送郵箱驗證碼
 * @param email 郵箱賬號
 * @param request
 * @return
 */
@ResponseBody
@RequestMapping(value = "/sendEmail",method = RequestMethod.POST)
public ResponseEntity sendEmail(String email, HttpServletRequest request){
    if(email==null||!ValidateUtils.isEmail(email)){
        return new ResponseEntity(400,"error","郵箱賬號錯誤!");
    }
    //發送注冊郵件
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+ request.getContextPath()+"/";
    Map<String,Object> modelMap=new HashMap<String,Object>();
    modelMap.put("USERNAME","baby慕慕");
    modelMap.put("LOGOIMG",basePath+"resources/img/logo.png");
    int verifyCode = RandomUtils.nextInt(100000, 999999);
    request.getSession().setAttribute("VERIFYCODE",String.valueOf(verifyCode));
    modelMap.put("VERIFYCODE",verifyCode);
    modelMap.put("IFORGOTURL",basePath+"system/iforget");
    modelMap.put("LOGINURL",basePath+"system/login");
    modelMap.put("OFFICIALURL",basePath);
    String content= VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "tpl/verifyCodeEmail.html","UTF-8",modelMap);
    try {
        boolean sendSuccess=emailService.send(email,null,"baby慕慕開放平台-驗證碼找回密碼",content);
        if(sendSuccess){
            return new ResponseEntity(200,"success","驗證碼發送成功");
        }
    } catch (EmailException e) {
        e.printStackTrace();
    }
    return new ResponseEntity(400,"error","郵箱發送失敗!");
}
 
開發者ID:babymm,項目名稱:mumu,代碼行數:35,代碼來源:SysIforgetController.java

示例12: sendRandomCode

import org.apache.commons.lang3.RandomUtils; //導入方法依賴的package包/類
/** 發送驗證碼 */
private void sendRandomCode(String sender, SendMsg sendMsg, String cacheKey) {
	Integer random = RandomUtils.nextInt(123456, 999999);
	Map<String, String> param = InstanceUtil.newHashMap();
	param.put("code", random.toString());
	param.put("product", sender);
	if ("6".equals(sendMsg.getMsgType())) {
		param.put("", sendMsg.getParams());
	}
	sendMsg.setParams(JSON.toJSONString(param));
	CacheUtil.getCache().set(cacheKey, random.toString(), 60);
}
 
開發者ID:youngMen1,項目名稱:JAVA-,代碼行數:13,代碼來源:SendMsgService.java

示例13: range

import org.apache.commons.lang3.RandomUtils; //導入方法依賴的package包/類
protected <T> T range(String min, String max, Class<T> type) throws Exception {
    int randVal = RandomUtils.nextInt(valueOf(min), valueOf(max));
    return ReflectionUtils.stringToNumber(randVal, type);
}
 
開發者ID:randomito,項目名稱:randomito-all,代碼行數:5,代碼來源:BaseRangeAnnotationPostProcessor.java

示例14: generate

import org.apache.commons.lang3.RandomUtils; //導入方法依賴的package包/類
@Override
public Object generate(DefaultContext ctx) throws Exception {
    Object[] enums = ctx.getField().getType().getEnumConstants();
    return enums[RandomUtils.nextInt(0, enums.length)];
}
 
開發者ID:randomito,項目名稱:randomito-all,代碼行數:6,代碼來源:EnumGenerator.java

示例15: select

import org.apache.commons.lang3.RandomUtils; //導入方法依賴的package包/類
@Override
public ProviderService select(List<ProviderService> providerServices) {
    int MAX_LEN = providerServices.size();
    int index = RandomUtils.nextInt(0, MAX_LEN - 1);
    return providerServices.get(index);
}
 
開發者ID:linuer,項目名稱:nan,代碼行數:7,代碼來源:RandomLoadBalanceStrategyImpl.java


注:本文中的org.apache.commons.lang3.RandomUtils.nextInt方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。