Skip to content

Instantly share code, notes, and snippets.

@brunoborges
Created February 28, 2014 22:11
Show Gist options
  • Save brunoborges/9281070 to your computer and use it in GitHub Desktop.
Save brunoborges/9281070 to your computer and use it in GitHub Desktop.
public static Date randomShiftOnDate(Date someDate) {
Random random = new Random();
int randomValue = random.nextInt(31) * 60 * 1000; // 30 min.
boolean subtract = random.nextBoolean();
if (subtract) randomValue *= -1;
long time = someDate.getTime();
time += randomValue;
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(time);
return cal.getTime();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment