How do I generate random Time
values? For example: 07:02:33
, 08:52:14
, etc. I know how to generate random numbers but I don't know how to do this. I want to fill my database column TIME
with random values.
import java.util.Random;
import java.sql.Time;
final Random random = new Random();
final int millisInDay = 24*60*60*1000;
Time time = new Time((long)random.nextInt(millisInDay));
For your purposes this might be enough. Don't forget that some days have different lengths for which you might need to add test cases (daylight savings and leap seconds).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With