Java Code Examples for org.apache.commons.lang3.RandomUtils#nextFloat()

The following examples show how to use org.apache.commons.lang3.RandomUtils#nextFloat() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeleteDataFilesAction.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public void perform() throws Exception {
  getLogger().info("Start deleting data files");
  FileSystem fs = CommonFSUtils.getRootDirFileSystem(getConf());
  Path rootDir = CommonFSUtils.getRootDir(getConf());
  Path defaultDir = rootDir.suffix("/data/default");
  RemoteIterator<LocatedFileStatus> iterator =  fs.listFiles(defaultDir, true);
  while (iterator.hasNext()){
    LocatedFileStatus status = iterator.next();
    if(!HFile.isHFileFormat(fs, status.getPath())){
      continue;
    }
    if(RandomUtils.nextFloat(0, 100) > chance){
      continue;
    }
    fs.delete(status.getPath(), true);
    getLogger().info("Deleting {}", status.getPath());
  }
  getLogger().info("Done deleting data files");
}
 
Example 2
Source File: WriteIntoKafka.java    From flinkDemo with Apache License 2.0 5 votes vote down vote up
public static Float randmomUtils1(int i) throws Exception{
    Float value=RandomUtils.nextFloat(2950, 3080);
    switch (i){
        case 1:
            value=RandomUtils.nextFloat(10, 90);
            break;
        case 2:
            value=RandomUtils.nextFloat(0, 80);
            break;
    }
    return value;
}
 
Example 3
Source File: WriteIntoKafka.java    From flinkDemo with Apache License 2.0 5 votes vote down vote up
public static Float randmomUtils2(int i) throws Exception{
    Float value=RandomUtils.nextFloat(290, 300);
    switch (i){
        case 1:
            value=RandomUtils.nextFloat(0, 200);
            break;
    }
    return value;
}
 
Example 4
Source File: KafkaTests.java    From java-tutorial with MIT License 5 votes vote down vote up
@Test
    public void kafkaSend() throws InterruptedException {

        BizOperationLog log = new BizOperationLog();
        log.setAppId("jwell-omx");
        log.setAppName("运营管理系统");
        log.setFunction("修改订单编号");
        log.setOptTime(DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
        log.setOptUser("A总监-张建国");
        //发消息
        for (int i = 0; i < 4; i++) {
            String id = "SO" + Long.toString(RandomUtils.nextLong(10000000, 90000000));
            float price = RandomUtils.nextFloat(1000, 70000);
            BizData data = new BizData(id, price, "螺纹管");
            log.setBeforeModifyData(JSON.toJSONString(data));

            id = "SO" + Long.toString(RandomUtils.nextLong(10000000, 90000000));
            //改价格
//            price = RandomUtils.nextFloat(1000, 7000);
//            //改品名
//            data = new BizData(id, price, "矿石");
            data.setOrderId(id);
            log.setAfterModifyData(JSON.toJSONString(data));

            kafkaSender.send(log);
            Thread.sleep(500);
        }
    }
 
Example 5
Source File: Rogue.java    From piper with Apache License 2.0 5 votes vote down vote up
@Override
public Object handle(TaskExecution aTask) throws Exception {
  float nextFloat = RandomUtils.nextFloat(0, 1);
  float probability = aTask.getFloat("probability",0.5f);
  Assert.isTrue(probability>=0 && probability<=1,"probability must be a value between 0 and 1");
  if(nextFloat <= probability) {
    throw new IllegalStateException("I'm a rogue exception");
  }
  return null;
}
 
Example 6
Source File: CorruptDataFilesAction.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void perform() throws Exception {
  getLogger().info("Start corrupting data files");

  FileSystem fs = CommonFSUtils.getRootDirFileSystem(getConf());
  Path rootDir = CommonFSUtils.getRootDir(getConf());
  Path defaultDir = rootDir.suffix("/data/default");
  RemoteIterator<LocatedFileStatus> iterator =  fs.listFiles(defaultDir, true);
  while (iterator.hasNext()){
    LocatedFileStatus status = iterator.next();
    if(!HFile.isHFileFormat(fs, status.getPath())){
      continue;
    }
    if(RandomUtils.nextFloat(0, 100) > chance){
      continue;
    }

    FSDataOutputStream out = fs.create(status.getPath(), true);
    try {
      out.write(0);
    } finally {
      out.close();
    }
    getLogger().info("Corrupting {}", status.getPath());
  }
  getLogger().info("Done corrupting data files");
}
 
Example 7
Source File: AbstractDataSetIteratorTest.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
protected static Iterable<Pair<float[], float[]>> floatIterable(final int totalRows, final int numColumns) {
    return new Iterable<Pair<float[], float[]>>() {
        @Override
        public Iterator<Pair<float[], float[]>> iterator() {
            return new Iterator<Pair<float[], float[]>>() {
                private AtomicInteger cnt = new AtomicInteger(0);

                @Override
                public boolean hasNext() {
                    return cnt.incrementAndGet() <= totalRows;
                }

                @Override
                public Pair<float[], float[]> next() {
                    float features[] = new float[numColumns];
                    float labels[] = new float[numColumns];
                    for (int i = 0; i < numColumns; i++) {
                        features[i] = (float) i;
                        labels[i] = RandomUtils.nextFloat(0, 5);
                    }
                    return Pair.makePair(features, labels);
                }

                @Override
                public void remove() {
                    // no-op
                }
            };
        }
    };
}
 
Example 8
Source File: FastSerdeBenchmarkSupport.java    From avro-fastserde with Apache License 2.0 4 votes vote down vote up
public static Float getRandomFloat() {
    return RandomUtils.nextFloat(0f, Float.MAX_VALUE);
}