@Test public void shouldDrawFourtyNineAsMaximum() { LocalDate date = LocalDate.parse("2012-01-01"); LocalDate maxDate = LocalDate.parse("2013-01-01"); while (true) { Draw draw = DrawingService.drawNumbers(date); if (draw.getNumbers().contains(49)) { break; } date = date.plusDays(1); if (date.isAfter(maxDate)) { fail("didn't find 49 in the draw"); } } }
public static Draw drawNumbers(LocalDate date) { Random random = new Random(date.toEpochDay()); Draw.DrawBuilder builder = Draw.builder().withDate(date); do { Integer number = random.nextInt(MAX_NUMBER_IN_DRAW + 1); if (number < MIN_NUMBER_IN_DRAW) { continue; } if (builder.contains(number)) { continue; } builder.withNumber(number); } while (!builder.isComplete()); return builder.build(); }
DrawingService { public static Draw drawNumbers(LocalDate date) { Random random = new Random(date.toEpochDay()); Draw.DrawBuilder builder = Draw.builder().withDate(date); do { Integer number = random.nextInt(MAX_NUMBER_IN_DRAW + 1); if (number < MIN_NUMBER_IN_DRAW) { continue; } if (builder.contains(number)) { continue; } builder.withNumber(number); } while (!builder.isComplete()); return builder.build(); } }
DrawingService { public static Draw drawNumbers(LocalDate date) { Random random = new Random(date.toEpochDay()); Draw.DrawBuilder builder = Draw.builder().withDate(date); do { Integer number = random.nextInt(MAX_NUMBER_IN_DRAW + 1); if (number < MIN_NUMBER_IN_DRAW) { continue; } if (builder.contains(number)) { continue; } builder.withNumber(number); } while (!builder.isComplete()); return builder.build(); }  }
DrawingService { public static Draw drawNumbers(LocalDate date) { Random random = new Random(date.toEpochDay()); Draw.DrawBuilder builder = Draw.builder().withDate(date); do { Integer number = random.nextInt(MAX_NUMBER_IN_DRAW + 1); if (number < MIN_NUMBER_IN_DRAW) { continue; } if (builder.contains(number)) { continue; } builder.withNumber(number); } while (!builder.isComplete()); return builder.build(); }  static Draw drawNumbers(LocalDate date); }
DrawingService { public static Draw drawNumbers(LocalDate date) { Random random = new Random(date.toEpochDay()); Draw.DrawBuilder builder = Draw.builder().withDate(date); do { Integer number = random.nextInt(MAX_NUMBER_IN_DRAW + 1); if (number < MIN_NUMBER_IN_DRAW) { continue; } if (builder.contains(number)) { continue; } builder.withNumber(number); } while (!builder.isComplete()); return builder.build(); }  static Draw drawNumbers(LocalDate date); static final int MAX_NUMBER_IN_DRAW; static final int MIN_NUMBER_IN_DRAW; }