diff --git a/CreateMeasurements.java b/CreateMeasurements.java index 94b3ff2..1b75349 100644 --- a/CreateMeasurements.java +++ b/CreateMeasurements.java @@ -13,21 +13,21 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package dev.morling.onebrc; +// package dev.morling.onebrc; import java.io.BufferedWriter; import java.nio.file.Files; import java.nio.file.Path; import java.util.List; -import java.util.concurrent.ThreadLocalRandom; +import java.util.Random; public class CreateMeasurements { private static final Path MEASUREMENT_FILE = Path.of("./measurements.txt"); private record WeatherStation(String id, double meanTemperature) { - double measurement() { - double m = ThreadLocalRandom.current().nextGaussian(meanTemperature, 10); + double measurement(Random rnd) { + double m = rnd.nextGaussian(meanTemperature, 10); return Math.round(m * 10.0) / 10.0; } } @@ -35,18 +35,20 @@ public class CreateMeasurements { public static void main(String[] args) throws Exception { long start = System.currentTimeMillis(); - if (args.length != 1) { - System.out.println("Usage: create_measurements.sh "); + if (args.length != 2) { + System.out.println("Usage: create_measurements.sh "); System.exit(1); } int size = 0; + int seed = 0; try { size = Integer.parseInt(args[0]); + seed = Integer.parseInt(args[1]); } catch (NumberFormatException e) { - System.out.println("Invalid value for "); - System.out.println("Usage: CreateMeasurements "); + System.out.println("Invalid value for or "); + System.out.println("Usage: CreateMeasurements "); System.exit(1); } @@ -490,13 +492,14 @@ public class CreateMeasurements { new WeatherStation("Zürich", 9.3)); try (BufferedWriter bw = Files.newBufferedWriter(MEASUREMENT_FILE)) { + Random rnd = new Random(seed); for (int i = 0; i < size; i++) { if (i > 0 && i % 50_000_000 == 0) { System.out.printf("Wrote %,d measurements in %s ms%n", i, System.currentTimeMillis() - start); } - WeatherStation station = stations.get(ThreadLocalRandom.current().nextInt(stations.size())); + WeatherStation station = stations.get(rnd.nextInt(stations.size())); bw.write(station.id()); - bw.write(";" + station.measurement()); + bw.write(";" + station.measurement(rnd)); bw.write('\n'); } }