/** * Generates a random birthday between two ages. * * @param minAge * the minimal age * @param maxAge * the maximal age * @return a random birthday between {@code minAge} and {@code maxAge} years ago. * @throws IllegalArgumentException * if the {@code maxAge} is lower than {@code minAge}. */ public Date birthday(int minAge, int maxAge) { int currentYear = Calendar.getInstance().get(Calendar.YEAR); Calendar from = new GregorianCalendar(currentYear - maxAge, 0, 1); Calendar to = new GregorianCalendar(currentYear - minAge, 11, 31); return between(from.getTime(), to.getTime()); }