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); } }
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 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)); } } }
public void run() throws InterruptedException { try { int number = random.nextInt()/10000; List<Integer> primeFactors = primeFactors(number); print(number, primeFactors); } catch (Exception e) { System.out.println(String.format("illegalArgumentCount:%3d, ", illegalArgumentCount) + e.getMessage()); } }
@Test public void shouldLoadProcedureFromJarWithSpacesInFilename() throws Throwable { // Given URL jar = new JarBuilder().createJarFor( tmpdir.newFile( new Random().nextInt() + " some spaces in filename.jar" ), ClassWithOneProcedure.class); // When List<CallableProcedure> procedures = jarloader.loadProceduresFromDir( parentDir( jar ) ).procedures(); // Then List<ProcedureSignature> signatures = procedures.stream().map( CallableProcedure::signature ).collect( toList() ); assertThat( signatures, contains( procedureSignature( "org", "neo4j", "kernel", "impl", "proc", "myProcedure" ).out( "someNumber", NTInteger ).build() ) ); assertThat( asList( procedures.get( 0 ).apply( new BasicContext(), new Object[0], resourceTracker ) ), contains( IsEqual.equalTo( new Object[]{1337L} ) ) ); }
/** * 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) }; } }
@Setup public void setup() { Random rand = ThreadLocalRandom.current(); sequences = new ArrayList<>(); for (int i = 0; i < count; i++) { int[] sequence = new int[sequenceLength]; for (int j = 0; j < sequenceLength; j++) { sequence[j] = rand.nextInt(); } sequences.add(Sequences.simple(Ints.asList(sequence))); } }
private static void runLeastOfComparison(int iterations, int elements, int seeds) { Random random = new Random(42); Ordering<Integer> ordering = Ordering.natural(); for (int i = 0; i < iterations; i++) { List<Integer> list = Lists.newArrayList(); for (int j = 0; j < elements; j++) { list.add(random.nextInt(10 * i + j + 1)); } for (int seed = 1; seed < seeds; seed++) { int k = random.nextInt(10 * seed); assertEquals(ordering.sortedCopy(list).subList(0, k), ordering.leastOf(list, k)); } } }