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


Java RandomUtils類代碼示例

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


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

示例1: selectTable

import org.apache.commons.lang.math.RandomUtils; //導入依賴的package包/類
protected HTableDescriptor selectTable(ConcurrentHashMap<TableName, HTableDescriptor> tableMap)
{
  // randomly select table from tableMap
  if (tableMap.isEmpty()){
    return null;
  }
  // synchronization to prevent removal from multiple threads
  synchronized (tableMap){
    ArrayList<TableName> tableList = new ArrayList<TableName>(tableMap.keySet());
    TableName randomKey = tableList.get(RandomUtils.nextInt(tableList.size()));
    HTableDescriptor randomHtd = tableMap.get(randomKey);
    // remove from tableMap
    tableMap.remove(randomKey);
    return randomHtd;
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:17,代碼來源:IntegrationTestDDLMasterFailover.java

示例2: randomSelect

import org.apache.commons.lang.math.RandomUtils; //導入依賴的package包/類
@Override
public WebElement randomSelect(Element ele)
{
	Select select = createSelect(ele);
	if(select != null)
	{
		List<WebElement> options = select.getOptions();
		if(CollectionUtils.isNotEmpty(options))
		{
			int count = options.size();
			int index = RandomUtils.nextInt(count);
			index = (index == 0 ? 1 : index); //通常第一個選項都是無效的選項

			select.selectByIndex(index);
			
			return options.get(index);
		}
	}
	
	return null;
}
 
開發者ID:LinuxSuRen,項目名稱:phoenix.webui.framework,代碼行數:22,代碼來源:SeleniumSelect.java

示例3: buildWorkerNode

import org.apache.commons.lang.math.RandomUtils; //導入依賴的package包/類
/**
 * Build worker node entity by IP and PORT
 */
private WorkerNodeEntity buildWorkerNode() {
    WorkerNodeEntity workerNodeEntity = new WorkerNodeEntity();
    if (DockerUtils.isDocker()) {
        workerNodeEntity.setType(WorkerNodeType.CONTAINER.value());
        workerNodeEntity.setHostName(DockerUtils.getDockerHost());
        workerNodeEntity.setPort(DockerUtils.getDockerPort());

    } else {
        workerNodeEntity.setType(WorkerNodeType.ACTUAL.value());
        workerNodeEntity.setHostName(NetUtils.getLocalAddress());
        workerNodeEntity.setPort(System.currentTimeMillis() + "-" + RandomUtils.nextInt(100000));
    }

    return workerNodeEntity;
}
 
開發者ID:baidu,項目名稱:uid-generator,代碼行數:19,代碼來源:DisposableWorkerIdAssigner.java

示例4: main

import org.apache.commons.lang.math.RandomUtils; //導入依賴的package包/類
public static void main(String[] args) {
		byte[] data=new byte[1024*1024];
		for(int i=0;i<data.length;i++)
		{
			data[i]=(byte) RandomUtils.nextInt(255);
		}
		Test t=new Test();
		Scanner sc=new Scanner(System.in);
		sc.nextLine();
//		t.testtMap(data);
//		sc.nextLine();
//		t.testMap(data);
//		sc.nextLine();
		t.testNMap(data);
		sc.nextLine();
	}
 
開發者ID:juebanlin,項目名稱:util4j,代碼行數:17,代碼來源:NodeMap5.java

示例5: main

import org.apache.commons.lang.math.RandomUtils; //導入依賴的package包/類
public static void main(String[] args) {
		byte[] data=new byte[1024*1024*1];
		for(int i=0;i<data.length;i++)
		{
			data[i]=(byte) RandomUtils.nextInt(255);
		}
		Scanner sc=new Scanner(System.in);
//		sc.nextLine();
//		new Test().testMap(data);
		sc.nextLine();
		Test t=new Test();
		t.testNMap(data);
		sc.nextLine();
	}
 
開發者ID:juebanlin,項目名稱:util4j,代碼行數:15,代碼來源:NodeMap.java

示例6: next

import org.apache.commons.lang.math.RandomUtils; //導入依賴的package包/類
@Override
public Node next() throws InterruptedException {
    List<Node> nodes = getAliveNodes();

    if (nodes == null || nodes.size() == 0) {
        return null;
    }

    Long nid = ArbitrateConfigUtils.getCurrentNid();
    Node current = new Node();
    current.setId(nid);

    // 判斷一下是否優先返回local
    boolean existLocal = nodes.remove(current);
    if (existLocal && nodes.size() == 0) {//如果隻有它自己
        return current;
    } else if (existLocal && RandomUtils.nextInt(100) < localPercent) {//計算一下百分比
        return current;
    } else {
        int index = RandomUtils.nextInt(nodes.size());
        return nodes.get(index);
    }

}
 
開發者ID:luoyaogui,項目名稱:otter-G,代碼行數:25,代碼來源:RandomLoadBalance.java

示例7: next

import org.apache.commons.lang.math.RandomUtils; //導入依賴的package包/類
public Node next() throws InterruptedException {
    List<Node> nodes = getAliveNodes();
    if (nodes == null || nodes.size() == 0) {
        return null;
    }

    Long nid = ArbitrateConfigUtils.getCurrentNid();
    Node current = new Node();
    current.setId(nid);

    // 判斷一下是否優先返回local
    boolean existLocal = nodes.remove(current);
    if (existLocal && nodes.size() == 0) {//如果隻有它自己
        return current;
    } else if (existLocal && RandomUtils.nextInt(100) < localPercent) {//計算一下百分比
        return current;
    } else {
        int number = round.incrementAndGet();
        if (number > MAX_ROUND) {
            number = round.getAndSet(0);
        }
        int index = (int) (number % nodes.size());
        return nodes.get(index);
    }

}
 
開發者ID:luoyaogui,項目名稱:otter-G,代碼行數:27,代碼來源:RoundRobinLoadBalance.java

示例8: test_simple

import org.apache.commons.lang.math.RandomUtils; //導入依賴的package包/類
@Test
public void test_simple() {
    int thread = 10;
    int count = 10;
    WeightController controller = new WeightController(thread);
    CountDownLatch latch = new CountDownLatch(thread);
    WeightWorkerTest[] workers = new WeightWorkerTest[thread];
    for (int i = 0; i < thread; i++) {
        int[] weights = new int[count];
        for (int j = 0; j < count; j++) {
            weights[j] = RandomUtils.nextInt(count);
        }
        workers[i] = new WeightWorkerTest(i, weights, controller, latch);
    }

    for (int i = 0; i < thread; i++) {
        workers[i].start();
    }

    try {
        latch.await();
    } catch (InterruptedException e) {
        want.fail();
    }
}
 
開發者ID:luoyaogui,項目名稱:otter-G,代碼行數:26,代碼來源:WeightControllerTest.java

示例9: createIntent

import org.apache.commons.lang.math.RandomUtils; //導入依賴的package包/類
private Intent createIntent(Key key, long mac, NodeId node, Multimap<NodeId, Device> devices) {
    // choose a random device for which this node is master
    List<Device> deviceList = devices.get(node).stream().collect(Collectors.toList());
    Device device = deviceList.get(RandomUtils.nextInt(deviceList.size()));

    //FIXME we currently ignore the path length and always use the same device
    TrafficSelector selector = DefaultTrafficSelector.builder()
            .matchEthDst(MacAddress.valueOf(mac)).build();
    TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
    ConnectPoint ingress = new ConnectPoint(device.id(), PortNumber.portNumber(1));
    ConnectPoint egress = new ConnectPoint(device.id(), PortNumber.portNumber(2));

    return PointToPointIntent.builder()
            .appId(appId)
            .key(key)
            .selector(selector)
            .treatment(treatment)
            .ingressPoint(ingress)
            .egressPoint(egress)
            .build();
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:22,代碼來源:IntentPerfInstaller.java

示例10: chore

import org.apache.commons.lang.math.RandomUtils; //導入依賴的package包/類
@Override protected void chore() {
  final StringBuffer whyFlush = new StringBuffer();
  for (Region r : this.server.onlineRegions.values()) {
    if (r == null) continue;
    if (((HRegion) r).shouldFlush(whyFlush)) {
      FlushRequester requester = server.getFlushRequester();
      if (requester != null) {
        long randomDelay = RandomUtils.nextInt(RANGE_OF_DELAY) + MIN_DELAY_TIME;
        LOG.info(getName() + " requesting flush of " + r.getRegionInfo().getRegionNameAsString()
            + " because " + whyFlush.toString() + " after random delay " + randomDelay + "ms");
        //Throttle the flushes by putting a delay. If we don't throttle, and there
        //is a balanced write-load on the regions in a table, we might end up
        //overwhelming the filesystem with too many flushes at once.
        requester.requestDelayedFlush(r, randomDelay, false);
      }
    }
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:19,代碼來源:HRegionServer.java

示例11: perform

import org.apache.commons.lang.math.RandomUtils; //導入依賴的package包/類
@Override
public void perform() throws Exception {
  HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
  Admin admin = util.getHBaseAdmin();
  boolean major = RandomUtils.nextInt(100) < majorRatio;

  LOG.info("Performing action: Compact table " + tableName + ", major=" + major);
  try {
    if (major) {
      admin.majorCompact(tableName);
    } else {
      admin.compact(tableName);
    }
  } catch (Exception ex) {
    LOG.warn("Compaction failed, might be caused by other chaos: " + ex.getMessage());
  }
  if (sleepTime > 0) {
    Thread.sleep(sleepTime);
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:21,代碼來源:CompactTableAction.java

示例12: run

import org.apache.commons.lang.math.RandomUtils; //導入依賴的package包/類
@Override
public void run() {
  // Add some jitter.
  int jitter = RandomUtils.nextInt((int) periodMs);
  LOG.info("Sleeping for " + jitter + " to add jitter");
  Threads.sleep(jitter);

  while (!isStopped()) {
    long start = System.currentTimeMillis();
    runOneIteration();

    if (isStopped()) return;
    long sleepTime = periodMs - (System.currentTimeMillis() - start);
    if (sleepTime > 0) {
      LOG.info("Sleeping for: " + sleepTime);
      Threads.sleep(sleepTime);
    }
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:20,代碼來源:PeriodicPolicy.java

示例13: selectWeightedRandomItem

import org.apache.commons.lang.math.RandomUtils; //導入依賴的package包/類
/** Selects a random item from the given items with weights*/
public static <T> T selectWeightedRandomItem(List<Pair<T, Integer>> items) {
  int totalWeight = 0;
  for (Pair<T, Integer> pair : items) {
    totalWeight += pair.getSecond();
  }

  int cutoff = RandomUtils.nextInt(totalWeight);
  int cummulative = 0;
  T item = null;

  //warn: O(n)
  for (int i=0; i<items.size(); i++) {
    int curWeight = items.get(i).getSecond();
    if ( cutoff < cummulative + curWeight) {
      item = items.get(i).getFirst();
      break;
    }
    cummulative += curWeight;
  }

  return item;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:24,代碼來源:PolicyBasedChaosMonkey.java

示例14: map

import org.apache.commons.lang.math.RandomUtils; //導入依賴的package包/類
@Override
public void map(LongWritable key, SamRecordWritable value,Context context) throws IOException, InterruptedException {
	SamRecordDatum datum = new SamRecordDatum();
	String rgID = SamRecordUtils.getReadGroup(value.get());
	GaeaSamRecord record = new GaeaSamRecord(mFileHeader, value.get());
	sampleName = mFileHeader.getReadGroup(rgID).getSample();
	if(datum.parseSam(record.getSAMString())) {
		long winNum = -1;
		winNum = datum.getPosition() / BamQualityControl.WINDOW_SIZE;
		formatKeyValue(datum, rgID, winNum, true);
		context.write(outK, outV);
		if (winNum != (datum.getEnd() / BamQualityControl.WINDOW_SIZE)) {
			winNum++; 
			formatKeyValue(datum, rgID, winNum, false);
			context.write(outK, outV);
		}
	} else {
		if(unmappedReadsNum > 10000) {
			randomkey = RandomUtils.nextInt();
			unmappedReadsNum = 0;
		}
		context.write(new Text(formatKey("-1:-1", randomkey)), new Text("1"));
		unmappedReadsNum++;
	}
}
 
開發者ID:BGI-flexlab,項目名稱:SOAPgaea,代碼行數:26,代碼來源:BamQualityControlMapper.java

示例15: nextData

import org.apache.commons.lang.math.RandomUtils; //導入依賴的package包/類
@Override
public Object nextData() {
    if (closed)
        throw new IllegalStateException("file closed..");
    int position = RandomUtils.nextInt(size - 1);
    ByteBuffer buffer = localBuffer.get();

    goNextNewLineHead(buffer, position);
    String[] obj = null;
    String line = readLine(buffer);
    if (needSplit) {
        if (lineSplit == null) {
            obj = StringUtils.split(line);
        } else {
            obj = StringUtils.split(line, lineSplit);
        }
        return obj;
    } else {
        return line;
    }
}
 
開發者ID:blusechen,項目名稱:venus,代碼行數:22,代碼來源:FileLineRandomData.java


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