当前位置: 首页>>代码示例>>Java>>正文


Java Random.setSeed方法代码示例

本文整理汇总了Java中java.util.Random.setSeed方法的典型用法代码示例。如果您正苦于以下问题:Java Random.setSeed方法的具体用法?Java Random.setSeed怎么用?Java Random.setSeed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.Random的用法示例。


在下文中一共展示了Random.setSeed方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testRandom

import java.util.Random; //导入方法依赖的package包/类
@Test
public void testRandom() throws Exception {
  Configuration conf = new Configuration();
  conf.setInt(Job.COMPLETION_POLL_INTERVAL_KEY, 100);
  Job job = Job.getInstance(conf);
  conf = job.getConfiguration();
  conf.setInt(MRJobConfig.IO_SORT_MB, 1);
  conf.setClass("test.mapcollection.class", RandomFactory.class,
      RecordFactory.class);
  final Random r = new Random();
  final long seed = r.nextLong();
  LOG.info("SEED: " + seed);
  r.setSeed(seed);
  conf.set(MRJobConfig.MAP_SORT_SPILL_PERCENT,
      Float.toString(Math.max(0.1f, r.nextFloat())));
  RandomFactory.setLengths(conf, r, 1 << 14);
  conf.setInt("test.spillmap.records", r.nextInt(500));
  conf.setLong("test.randomfactory.seed", r.nextLong());
  runTest("random", job);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:21,代码来源:TestMapCollection.java

示例2: generateWorld

import java.util.Random; //导入方法依赖的package包/类
/**
 * Callback hook for world gen - if your mod wishes to add extra mod related generation to the world
 * call this
 *
 * @param chunkX         Chunk X coordinate
 * @param chunkZ         Chunk Z coordinate
 * @param world          World we're generating into
 * @param chunkGenerator The chunk generator
 * @param chunkProvider  The chunk provider
 */
public static void generateWorld(int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider)
{
    if (sortedGeneratorList == null)
    {
        computeSortedGeneratorList();
    }
    long worldSeed = world.getSeed();
    Random fmlRandom = new Random(worldSeed);
    long xSeed = fmlRandom.nextLong() >> 2 + 1L;
    long zSeed = fmlRandom.nextLong() >> 2 + 1L;
    long chunkSeed = (xSeed * chunkX + zSeed * chunkZ) ^ worldSeed;

    for (IWorldGenerator generator : sortedGeneratorList)
    {
        fmlRandom.setSeed(chunkSeed);
        generator.generate(fmlRandom, chunkX, chunkZ, world, chunkGenerator, chunkProvider);
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:29,代码来源:GameRegistry.java

示例3: generate

import java.util.Random; //导入方法依赖的package包/类
@Override
public List<CostResource> generate(ArrayList<Object> parameters) {
	ArrayList<CostResource> resList = new ArrayList<CostResource>();
	
	NetworkStack ns = (NetworkStack)parameters.get(0);
	Integer minLC = ConversionHelper.paramObjectToInteger(parameters.get(1));
	Integer maxLC = ConversionHelper.paramObjectToInteger(parameters.get(2));
	Long seed = ConversionHelper.paramObjectToLong(parameters.get(3));
	
	Random random = new Random();
	random.setSeed(seed);
	
	SubstrateNetwork sNet = ns.getSubstrate();
	
	for (SubstrateLink l : sNet.getEdges()) {
		CostResource bw = new CostResource(l);
		int value = (int) (minLC + (maxLC
				- minLC + 1)
				* random.nextDouble());
		bw.setCost((double) value);
		l.add(bw);
		resList.add(bw);
	}
	
	return resList;
}
 
开发者ID:KeepTheBeats,项目名称:alevin-svn2,代码行数:27,代码来源:FixedCostResourceGenerator.java

示例4: generatePoints

import java.util.Random; //导入方法依赖的package包/类
@Override
public void generatePoints(World world, Random random, Rectangled rectangle, List<Vector2d> points) {
    final int minX = ((int) rectangle.getMin().getX()) >> 4;
    final int minZ = ((int) rectangle.getMin().getY()) >> 4;
    final int maxX = ((int) rectangle.getMax().getX()) >> 4;
    final int maxZ = ((int) rectangle.getMax().getY()) >> 4;
    final long worldSeed = world.getProperties().getSeed();
    for (int x = minX; x <= maxX; x++) {
        for (int z = minZ; z <= maxZ; z++) {
            random.setSeed(((long) x * 341873128712L + (long) z * 132897987541L) ^ worldSeed);
            final int xPos = x << 4;
            final int zPos = z << 4;
            this.parent.generatePoints(world, random, new Rectangled(new Vector2d(xPos, zPos), new Vector2d(xPos & 0xf, zPos & 0xf)), points);
        }
    }
}
 
开发者ID:LanternPowered,项目名称:Porygen,代码行数:17,代码来源:ChunkBasedPointsGenerator.java

示例5: eqSeedTest

import java.util.Random; //导入方法依赖的package包/类
static void eqSeedTest(GridmixRecord x, GridmixRecord y, int max)
    throws Exception {
  final Random r = new Random();
  final long s = r.nextLong();
  r.setSeed(s);
  LOG.info("eqSeed: " + s);
  assertEquals(x.fixedBytes(), y.fixedBytes());
  final int min = x.fixedBytes() + 1;
  final DataOutputBuffer out1 = new DataOutputBuffer();
  final DataOutputBuffer out2 = new DataOutputBuffer();
  for (int i = min; i < max; ++i) {
    final long seed = r.nextLong();
    setSerialize(x, seed, i, out1);
    setSerialize(y, seed, i, out2);
    assertEquals(x, y);
    assertEquals(x.hashCode(), y.hashCode());

    // verify written contents match
    assertEquals(out1.getLength(), out2.getLength());
    // assumes that writes will grow buffer deterministically
    assertEquals("Bad test", out1.getData().length, out2.getData().length);
    assertArrayEquals(out1.getData(), out2.getData());
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:25,代码来源:TestGridmixRecord.java

示例6: generate

import java.util.Random; //导入方法依赖的package包/类
@Override
public List<BandwidthResource> generate(ArrayList<Object> parameters) {
	ArrayList<BandwidthResource> resList = new ArrayList<BandwidthResource>();
	
	NetworkStack ns = (NetworkStack)parameters.get(0);
	Integer minBW = ConversionHelper.paramObjectToInteger(parameters.get(1));
	Integer maxBW = ConversionHelper.paramObjectToInteger(parameters.get(2));
	Long seed = ConversionHelper.paramObjectToLong(parameters.get(3)); 
	
	Random random = new Random();
	random.setSeed(seed);
	
	SubstrateNetwork sNet = ns.getSubstrate();
	
	for (SubstrateLink l : sNet.getEdges()) {
		BandwidthResource bw = new BandwidthResource(l);
                       int value = (int) (minBW + random.nextInt(maxBW - minBW + 1));
		bw.setBandwidth((double) value);
		l.add(bw);
		resList.add(bw);
	}
	
	return resList;
}
 
开发者ID:KeepTheBeats,项目名称:alevin-svn2,代码行数:25,代码来源:FixedBandwidthResourceGenerator.java

示例7: getFixedRandomIndices

import java.util.Random; //导入方法依赖的package包/类
/**
 * Creates the same random sequence of indexes. To be used to select strings by {@link
 * #createFixedRandomStrings(int)}.
 */
public static int[] getFixedRandomIndices(int count, int maxIndex) {
    int[] indices = new int[count];

    Random random = new Random();
    random.setSeed(StringGenerator.SEED);

    for (int i = 0; i < count; i++) {
        indices[i] = random.nextInt(maxIndex + 1);
    }

    return indices;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:StringGenerator.java

示例8: binSortTest

import java.util.Random; //导入方法依赖的package包/类
static void binSortTest(GridmixRecord x, GridmixRecord y, int min,
    int max, WritableComparator cmp) throws Exception {
  final Random r = new Random();
  final long s = r.nextLong();
  r.setSeed(s);
  LOG.info("sort: " + s);
  final DataOutputBuffer out1 = new DataOutputBuffer();
  final DataOutputBuffer out2 = new DataOutputBuffer();
  for (int i = min; i < max; ++i) {
    final long seed1 = r.nextLong();
    setSerialize(x, seed1, i, out1);
    assertEquals(0, x.compareSeed(seed1, Math.max(0, i - x.fixedBytes())));

    final long seed2 = r.nextLong();
    setSerialize(y, seed2, i, out2);
    assertEquals(0, y.compareSeed(seed2, Math.max(0, i - x.fixedBytes())));

    // for eq sized records, ensure byte cmp where req
    final int chk = WritableComparator.compareBytes(
        out1.getData(), 0, out1.getLength(),
        out2.getData(), 0, out2.getLength());
    assertEquals(Integer.signum(chk), Integer.signum(x.compareTo(y)));
    assertEquals(Integer.signum(chk), Integer.signum(cmp.compare(
          out1.getData(), 0, out1.getLength(),
          out2.getData(), 0, out2.getLength())));
    // write second copy, compare eq
    final int s1 = out1.getLength();
    x.write(out1);
    assertEquals(0, cmp.compare(out1.getData(), 0, s1,
          out1.getData(), s1, out1.getLength() - s1));
    final int s2 = out2.getLength();
    y.write(out2);
    assertEquals(0, cmp.compare(out2.getData(), 0, s2,
          out2.getData(), s2, out2.getLength() - s2));
    assertEquals(Integer.signum(chk), Integer.signum(cmp.compare(out1.getData(), 0, s1,
          out2.getData(), s2, out2.getLength() - s2)));
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:39,代码来源:TestGridmixRecord.java

示例9: testGzipCompatibility

import java.util.Random; //导入方法依赖的package包/类
@Test
public void testGzipCompatibility() throws IOException {
  Random r = new Random();
  long seed = r.nextLong();
  r.setSeed(seed);
  LOG.info("seed: " + seed);

  DataOutputBuffer dflbuf = new DataOutputBuffer();
  GZIPOutputStream gzout = new GZIPOutputStream(dflbuf);
  byte[] b = new byte[r.nextInt(128 * 1024 + 1)];
  r.nextBytes(b);
  gzout.write(b);
  gzout.close();

  DataInputBuffer gzbuf = new DataInputBuffer();
  gzbuf.reset(dflbuf.getData(), dflbuf.getLength());

  Configuration conf = new Configuration();
  // don't use native libs
  ZlibFactory.setNativeZlibLoaded(false);
  CompressionCodec codec = ReflectionUtils.newInstance(GzipCodec.class, conf);
  Decompressor decom = codec.createDecompressor();
  assertNotNull(decom);
  assertEquals(BuiltInGzipDecompressor.class, decom.getClass());
  InputStream gzin = codec.createInputStream(gzbuf, decom);

  dflbuf.reset();
  IOUtils.copyBytes(gzin, dflbuf, 4096);
  final byte[] dflchk = Arrays.copyOf(dflbuf.getData(), dflbuf.getLength());
  assertArrayEquals(b, dflchk);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:32,代码来源:TestCodec.java

示例10: generateBigRR

import java.util.Random; //导入方法依赖的package包/类
public static ReservationDefinition generateBigRR(Random rand, long i) {
  rand.setSeed(i);
  long now = System.currentTimeMillis();

  // start time at random in the next 2 hours
  long arrival = rand.nextInt(2 * 3600 * 1000);
  // deadline at random in the next day
  long deadline = rand.nextInt(24 * 3600 * 1000);

  // create a request with a single atomic ask
  ReservationDefinition rr = new ReservationDefinitionPBImpl();
  rr.setArrival(now + arrival);
  rr.setDeadline(now + deadline);

  int gang = 1;
  int par = 100000; // 100k tasks
  long dur = rand.nextInt(60 * 1000); // 1min tasks
  ReservationRequest r =
      ReservationRequest.newInstance(Resource.newInstance(1024, 1, 1), par,
          gang, dur);
  ReservationRequests reqs = new ReservationRequestsPBImpl();
  reqs.setReservationResources(Collections.singletonList(r));
  rand.nextInt(3);
  ReservationRequestInterpreter[] type =
      ReservationRequestInterpreter.values();
  reqs.setInterpreter(type[rand.nextInt(type.length)]);
  rr.setReservationRequests(reqs);

  return rr;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:31,代码来源:ReservationSystemTestUtil.java

示例11: func_191068_a

import java.util.Random; //导入方法依赖的package包/类
public static void func_191068_a(long p_191068_0_, Random p_191068_2_, int p_191068_3_, int p_191068_4_)
{
    p_191068_2_.setSeed(p_191068_0_);
    long i = p_191068_2_.nextLong();
    long j = p_191068_2_.nextLong();
    long k = (long)p_191068_3_ * i;
    long l = (long)p_191068_4_ * j;
    p_191068_2_.setSeed(k ^ l ^ p_191068_0_);
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:10,代码来源:MapGenBase.java

示例12: generateAnnouncementId

import java.util.Random; //导入方法依赖的package包/类
public static String generateAnnouncementId() {
	SecureRandom secRand = new SecureRandom();
	Random rand = new Random();
	char[] buff = new char[9];

	for (int i = 0; i < 9; ++i) {
		// reseed rand once you've used up all available entropy bits
		if ((i % 10) == 0) {
			rand.setSeed(secRand.nextLong()); // 64 bits of random!
		}
		buff[i] = VALID_CHARS_2[rand.nextInt(VALID_CHARS_2.length)];
	}
	return "a" + new String(buff);
}
 
开发者ID:NovaFox161,项目名称:DisCal-Discord-Bot,代码行数:15,代码来源:KeyGenerator.java

示例13: generate

import java.util.Random; //导入方法依赖的package包/类
@Override
public List<MultiCoreEnergyResource> generate(ArrayList<Object> parameters) {
	ArrayList<MultiCoreEnergyResource> resList = new ArrayList<MultiCoreEnergyResource>();
	
	NetworkStack ns = (NetworkStack)parameters.get(0);
	Integer minIdle = ConversionHelper.paramObjectToInteger(parameters.get(1));
	Integer maxIdle = ConversionHelper.paramObjectToInteger(parameters.get(2));
	Integer minAdditional= ConversionHelper.paramObjectToInteger(parameters.get(3));
	Integer maxAdditional = ConversionHelper.paramObjectToInteger(parameters.get(4));
	Integer minCores= ConversionHelper.paramObjectToInteger(parameters.get(5));
	Integer maxCores = ConversionHelper.paramObjectToInteger(parameters.get(6));
	Long seed = ConversionHelper.paramObjectToLong(parameters.get(7));
	
	Random random = new Random();
	random.setSeed(seed);
	
	
	SubstrateNetwork sn = ns.getSubstrate();
	
	for(SubstrateNode n : sn.getVertices()) {
		int valueIdle = (int) (minIdle + (maxIdle
				- minIdle + 1)
				* random.nextDouble());
		int valueAdditional = (int) (minAdditional + (maxAdditional
				- minAdditional + 1)
				* random.nextDouble());
		int valueCores = (int) (minCores + (maxCores
				- minCores + 1)
				* random.nextDouble());
		MultiCoreEnergyResource cpu = new MultiCoreEnergyResource(n, valueIdle, valueAdditional, valueCores);
		n.add(cpu);
		resList.add(cpu);
	}
	
	return resList;
}
 
开发者ID:KeepTheBeats,项目名称:alevin-svn2,代码行数:37,代码来源:FixedMultiCoreEnergyResourceGenerator.java

示例14: setup

import java.util.Random; //导入方法依赖的package包/类
@Before
@SuppressWarnings("unchecked")
public void setup() {
  conf = new Configuration(false);
  conf.setLong(WAIT_TIME_BEFORE_KILL, 10000);
  conf.setLong(MONITORING_INTERVAL, 3000);
  // report "ideal" preempt
  conf.setFloat(TOTAL_PREEMPTION_PER_ROUND, (float) 1.0);
  conf.setFloat(NATURAL_TERMINATION_FACTOR, (float) 1.0);
  conf.set(YarnConfiguration.RM_SCHEDULER_MONITOR_POLICIES,
      ProportionalCapacityPreemptionPolicy.class.getCanonicalName());
  conf.setBoolean(YarnConfiguration.RM_SCHEDULER_ENABLE_MONITORS, true);
  // FairScheduler doesn't support this test,
  // Set CapacityScheduler as the scheduler for this test.
  conf.set("yarn.resourcemanager.scheduler.class",
      CapacityScheduler.class.getName());

  mClock = mock(Clock.class);
  mCS = mock(CapacityScheduler.class);
  when(mCS.getResourceCalculator()).thenReturn(rc);
  lm = mock(RMNodeLabelsManager.class);
  schedConf = new CapacitySchedulerConfiguration();
  when(mCS.getConfiguration()).thenReturn(schedConf);
  rmContext = mock(RMContext.class);
  when(mCS.getRMContext()).thenReturn(rmContext);
  when(rmContext.getNodeLabelManager()).thenReturn(lm);
  mDisp = mock(EventHandler.class);
  rand = new Random();
  long seed = rand.nextLong();
  System.out.println(name.getMethodName() + " SEED: " + seed);
  rand.setSeed(seed);
  appAlloc = 0;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:34,代码来源:TestProportionalCapacityPreemptionPolicy.java

示例15: testGzipCompatibility

import java.util.Random; //导入方法依赖的package包/类
@Test
public void testGzipCompatibility() throws IOException {
  Random r = new Random();
  long seed = r.nextLong();
  r.setSeed(seed);
  LOG.info("seed: " + seed);

  DataOutputBuffer dflbuf = new DataOutputBuffer();
  GZIPOutputStream gzout = new GZIPOutputStream(dflbuf);
  byte[] b = new byte[r.nextInt(128 * 1024 + 1)];
  r.nextBytes(b);
  gzout.write(b);
  gzout.close();

  DataInputBuffer gzbuf = new DataInputBuffer();
  gzbuf.reset(dflbuf.getData(), dflbuf.getLength());

  Configuration conf = new Configuration();
  conf.setBoolean(CommonConfigurationKeys.IO_NATIVE_LIB_AVAILABLE_KEY, false);
  CompressionCodec codec = ReflectionUtils.newInstance(GzipCodec.class, conf);
  Decompressor decom = codec.createDecompressor();
  assertNotNull(decom);
  assertEquals(BuiltInGzipDecompressor.class, decom.getClass());
  InputStream gzin = codec.createInputStream(gzbuf, decom);

  dflbuf.reset();
  IOUtils.copyBytes(gzin, dflbuf, 4096);
  final byte[] dflchk = Arrays.copyOf(dflbuf.getData(), dflbuf.getLength());
  assertArrayEquals(b, dflchk);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:31,代码来源:TestCodec.java


注:本文中的java.util.Random.setSeed方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。