public static void main(String[] args) throws InterruptedException { List<Pojo> list = new ArrayList<Pojo>(); for (int i = 0; i < 40; i ++) { Pojo pojo = new Pojo(); pojo.setName("name " + i); pojo.setAge(i + 2); list.add(pojo); } System.out.println(p); while (true) { int random = new Random().nextInt(40); String name = list.get(random).getName(); list.get(random).setName(null); test(list); list.get(random).setName(name); Thread.sleep(1000L); } }
@Test(timeout = 30000) public void flatMapRangeMixedAsyncLoop() { for (int i = 0; i < 2000; i++) { if (i % 10 == 0) { System.out.println("flatMapRangeAsyncLoop > " + i); final Random rnd = new Random(); @Override public Observable<Integer> apply(Integer t) { System.out.println(to.valueCount()); if (list.size() < 1000) { Set<Integer> set = new HashSet<Integer>(list); for (int j = 0; j < 1000; j++) { if (!set.contains(j)) { System.out.println(j + " missing"); assertEquals(1000, list.size());
public void testArbitrary_withCollisions() { List<Integer> list = Lists.newArrayList(); for (int i = 0; i < 50; i++) { list.add(i); } Ordering<Object> arbitrary = new ArbitraryOrdering() { @Override int identityHashCode(Object object) { return ((Integer) object) % 5; // fake tons of collisions! } }; // Don't let the elements be in such a predictable order list = shuffledCopy(list, new Random(1)); Collections.sort(list, arbitrary); // Now we don't care what order it's put the list in, only that // comparing any pair of elements gives the answer we expect. Helpers.testComparator(arbitrary, list); }
public static void main(String[] args) { Properties config = StringUtils.argsToProperties(args); log.info(config); boolean fullSentence = PropertiesUtils.getBool(config, "fullSentence", false); Random random = new Random(); String tagSeparator = config.getProperty("tagSeparator", TaggerConfig.TAG_SEPARATOR); TaggedFileRecord record = TaggedFileRecord.createRecord(config, config.getProperty("input")); for (List<TaggedWord> sentence : record.reader()) { int len = random.nextInt(sentence.size()) + 1; System.out.println(SentenceUtils.listToString(sentence.subList(0, len), false, tagSeparator)); if (fullSentence) { System.out.println(SentenceUtils.listToString(sentence, false, tagSeparator)); } } }
int[] array = new int[10]; Random rand = new Random(); for (int i = 0; i < array.length; i++) array[i] = rand.nextInt(100) + 1; Arrays.sort(array); System.out.println(Arrays.toString(array)); // in reverse order for (int i = array.length - 1; i >= 0; i--) System.out.print(array[i] + " "); System.out.println();
public void testPercentiles_indexes_varargsAll_compute_doubleCollection() { ArrayList<Integer> indexes = new ArrayList<>(); ImmutableMap.Builder<Integer, Double> expectedBuilder = ImmutableMap.builder(); for (int index = 0; index <= 100; index++) { indexes.add(index); expectedBuilder.put(index, expectedLargeDatasetPercentile(index)); } Random random = new Random(770683168895677741L); Collections.shuffle(indexes, random); assertThat(percentiles().indexes(Ints.toArray(indexes)).compute(PSEUDORANDOM_DATASET)) .comparingValuesUsing(QUANTILE_CORRESPONDENCE) .containsExactlyEntriesIn(expectedBuilder.build()); }
@Test public void testTimeSequence() throws Exception { Random r = new Random(); Instant[] times = new Instant[10]; for (int i = 0; i < times.length; i++) { times[i] = TimestampProviders.NANO.getTime(); if (i > 0) assertTrue(times[i] + " > " + times[i - 1], times[i].compareTo(times[i - 1])>0); Thread.sleep(r.nextInt(50) + 2); } }
@Test public void testOrderByWithLimit() { List<String> expected = rawInput.subList(0, Math.min(limit, rawInput.size())); List<String> inputs = Lists.newArrayList(rawInput); Collections.shuffle(inputs, new Random(2)); Sequence<String> result = new TopNSequence<String>(Sequences.simple(inputs), ordering, limit); Assert.assertEquals(expected, result.toList()); } }
@Test public void shouldWorkOnARandomArray() throws Exception { int[] numbers = new Random().ints(100000, 1, 100000).toArray(); long start = System.currentTimeMillis(); int[] pairs = Problem01.twoSum(numbers, 100); long end = System.currentTimeMillis(); System.out.println(String.format("Total time taken %d sec(s)", (end - start) / 1000)); System.out.println(Arrays.toString(pairs)); assertThat(pairs.length, equalTo(2)); }
import objectexplorer.ObjectGraphMeasurer; public class Measurer { public static void main(String[] args) { Set<Integer> hashset = new HashSet<Integer>(); Random rng = new Random(); int n = 10000; for (int i = 1; i <= n; i++) { hashset.add(random.nextInt()); } System.out.println(ObjectGraphMeasurer.measure(hashset)); } }
/** * Creates a two task assignment by selecting random tasks. */ public int[] createAssignment(List<Integer> tasks, byte[] key) { // It is necessary that this produce a deterministic assignment based on the key, so seed the Random from the key final long seedForRandom = Arrays.hashCode(key); final Random random = new Random(seedForRandom); final int choice1 = random.nextInt(tasks.size()); int choice2 = random.nextInt(tasks.size()); // ensure that choice1 and choice2 are not the same task choice2 = choice1 == choice2 ? (choice2 + 1) % tasks.size() : choice2; return new int[]{ tasks.get(choice1), tasks.get(choice2) }; } }