public void randomize () { for (TIntObjectIterator<int[]> it = offsets.iterator(); it.hasNext();) { it.advance(); int[] newVal = new int[it.value().length]; RaptorWorkerTimetable tt = data.timetablesForPattern.get(it.key()); for (int i = 0; i < newVal.length; i++) { newVal[i] = mt.nextInt(tt.headwaySecs[i]); } it.setValue(newVal); } } }
@Override public int nextInt(int lowerBound, int upperBound) { return lowerBound + rnd.nextInt((upperBound - lowerBound) + 1) ; }
public int nextInt() { return this.myPrg.nextInt(); }
public int nextInt(int range) { return this.myPrg.nextInt(range); }
private ArrayList<Integer> generateDepartureTimesToSample (ProfileRequest request) { // See Owen and Jiang 2016 (unfortunately no longer available online), add between f / 2 and // f + f / 2, where f is the mean step. int randomWalkStepMean = (request.toTime - request.fromTime) / request.monteCarloDraws; int randomWalkStepWidthOneSided = randomWalkStepMean / 2; ArrayList<Integer> departureTimes = new ArrayList<>(); for (int departureTime = request.fromTime + mersenneTwister.nextInt(randomWalkStepMean); departureTime < request.toTime; departureTime += mersenneTwister.nextInt(randomWalkStepMean) + randomWalkStepWidthOneSided) { departureTimes.add(departureTime); } return departureTimes; }
private ArrayList<Integer> generateDepartureTimesToSample (ProfileRequest request) { // See Owen and Jiang 2016 (unfortunately no longer available online), add between f / 2 and // f + f / 2, where f is the mean step. int randomWalkStepMean = (request.toTime - request.fromTime) / request.monteCarloDraws; int randomWalkStepWidthOneSided = randomWalkStepMean / 2; ArrayList<Integer> departureTimes = new ArrayList<>(); for (int departureTime = request.fromTime + mersenneTwister.nextInt(randomWalkStepMean); departureTime < request.toTime; departureTime += mersenneTwister.nextInt(randomWalkStepMean) + randomWalkStepWidthOneSided) { departureTimes.add(departureTime); } return departureTimes; }
/** * @return the next pseudorandom Geometric with distribution parameter p. Should be more * efficient than using logs. */ public int nextGeometric(double p) { if (p <= 0) throw new IllegalArgumentException("parameter of Geometric Distribution must be positive"); int value = myPrg.nextInt(); double sample = (double) Math.abs(value) / Integer.MAX_VALUE; return (int) (Math.floor((Math.log(1 - sample) / Math.log(1-p) ) )) + 1; }
/** * Helper method that generates a List of random alphanumeric strings. * @param suppSize Number of strings * @param length Size of each string. */ public static List<String> randStringList(int suppSize, int length) { String aToZ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; MersenneTwister random = new MersenneTwister(2); ArrayList<String> names = new ArrayList<String>(); for (int i = 0; i < suppSize; i++) { StringBuilder nextName = new StringBuilder(); for (int j = 0; j < length; j++) { int index = random.nextInt(aToZ.length()); nextName.append(aToZ.charAt(index)); } names.add(nextName.toString()); } return names; }
MersenneTwister rng = new MersenneTwister(); rng.setSeed(new int[] {1234567890}); System.out.println(rng.nextInt(Integer.MAX_VALUE)); // 1977150888
char[] chars = new char[length]; for (int i = 0; i < length; i++) { chars[i] = (char) ('a' + twister.nextInt(26));
val[tripScheduleIndex][frequencyEntryIndex] = mt.nextInt(schedule.headwaySeconds[frequencyEntryIndex]); remaining--;
val[tripScheduleIndex][frequencyEntryIndex] = mt.nextInt(schedule.headwaySeconds[frequencyEntryIndex]); remaining--;