Random Time Generator
Generate random times in 12h or 24h format with custom ranges, seconds, milliseconds, and batch generation. Cryptographically secure randomness.
About
Generating uniformly distributed random times is less trivial than it appears. A naive approach using separate random calls for hours, minutes, and seconds produces skewed distributions when constrained to a sub-range. This tool maps the entire valid time span to a linear range of total seconds (or milliseconds), generates a single cryptographically secure random offset via crypto.getRandomValues(), then decomposes the result back into h, m, s, and ms components. This guarantees uniform probability across every representable instant within your specified window.
Common applications include test-data seeding for scheduling software, randomized exam or quiz timing, Monte Carlo simulations of arrival processes, and fair assignment of time slots. The generator supports both 12-hour and 24-hour formats, optional seconds and milliseconds precision, uniqueness constraints, and batch output up to 1000 values. Note: when uniqueness is enabled with millisecond precision disabled, the pool is limited to 86,400 distinct values per day. Requesting more unique times than the pool size will be capped automatically.
Formulas
The generator converts the user-defined time range into a linear integer domain, samples uniformly, then maps back to time components.
Ttotal = tmax β tmin
r = cryptoRand(0, Ttotal)
t = tmin + r
Decomposition from total seconds t:
h = floor(t Γ· 3600)
m = floor((t β h Γ 3600) Γ· 60)
s = t β h Γ 3600 β m Γ 60
When millisecond precision is enabled, the domain expands to total milliseconds (Ttotal Γ 1000), and ms = t mod 1000. The cryptographic random integer is generated via crypto.getRandomValues() with rejection sampling to eliminate modulo bias: a 32-bit unsigned integer is drawn, and values exceeding the largest multiple of Ttotal that fits in 232 are discarded and redrawn.
Where tmin = start of range in seconds (or ms), tmax = end of range, r = uniform random offset, h = hours, m = minutes, s = seconds, ms = milliseconds.
Reference Data
| Preset | Range | Format | Use Case |
|---|---|---|---|
| Full Day | 00:00 - 23:59 | 24h | General purpose, simulations |
| Business Hours | 09:00 - 17:00 | 24h | Office scheduling, meetings |
| Morning | 06:00 - 11:59 | 12h | Alarm testing, wake-up routines |
| Afternoon | 12:00 - 17:59 | 12h | Appointment slots |
| Evening | 18:00 - 22:59 | 24h | Event scheduling, dinner reservations |
| Night Shift | 22:00 - 05:59 | 24h | Shift rotation, security patrols |
| School Hours | 08:00 - 15:00 | 12h | Class scheduling, bell times |
| Lunch Window | 11:30 - 13:30 | 12h | Break assignment, restaurant sims |
| Peak Traffic | 07:00 - 09:00 | 24h | Traffic simulation, load testing |
| Late Night | 23:00 - 03:59 | 24h | Nightlife, server maintenance windows |
| Exact Noon Β±1h | 11:00 - 13:00 | 24h | Solar studies, shadow calculations |
| Dawn | 04:30 - 06:30 | 24h | Photography, astronomy |
| Dusk | 17:30 - 20:30 | 24h | Sunset events, lighting tests |
| Full Day (ms) | 00:00:00.000 - 23:59:59.999 | 24h | High-precision test data |