RandomTime

RandomTime[]

gives a pseudorandom time of day.

RandomTime[{timemin,timemax}]

gives a pseudorandom time between the times timemin and timemax.

RandomTime[time]

gives a pseudorandom times between the start and end of the time period time.

RandomTime[quantity]

gives a pseudorandom time between now and the time quantity duration from now.

RandomTime[range,n]

gives a list of n pseudorandom times.

Details and Options

  • RandomTime is used to generate time objects within a particular time period (i.e. a given hour, minute, second or a set of arbitrary points in time).
  • RandomTime[{timemin,timemax}] chooses times with a uniform probability distribution between timemin and timemax.
  • RandomTime[time] gives a time between the beginning and end of the specified time, based on its granularity, and is equivalent to RandomTime[DateBounds[time]]. Specifications for time may be a DateObject, TimeObject or DateInterval.
  • RandomTime[quantity] gives a time between Now and Now+quantity, where quantity is a duration specified using Quantity with a time unit. RandomTime[{quantitymin,quantitymax}] gives a time between Now+quantitymin and Now+quantitymax.
  • RandomTime[range,{n1,n2,}] gives an n1×n2× array of pseudorandom times.
  • The following options can be specified for generated times:
  • DateGranularity Automaticgranularity of generated times
    TimeZone Automatictime zone of generated times
  • RandomTime gives a different sequence of pseudorandom times whenever you run the Wolfram Language. You can start with a particular seed using SeedRandom.

Examples

open allclose all

Basic Examples  (7)

A random time of the day:

A random time between 6am and 4pm:

A random time between noon and 1pm:

A random time between now and 3 hours from now:

A random time in the past two minutes:

A random time between the next hour and the hour after:

Five random times between 3 and 4am:

Options  (2)

DateGranularity  (1)

By default, times are generated with "Instant" granularity:

Use DateGranularity"Minute" to generate a pseudorandom minute:

TimeZone  (1)

Generate times in Lima's time zone:

Wolfram Research (2022), RandomTime, Wolfram Language function, https://reference.wolfram.com/language/ref/RandomTime.html.

Text

Wolfram Research (2022), RandomTime, Wolfram Language function, https://reference.wolfram.com/language/ref/RandomTime.html.

CMS

Wolfram Language. 2022. "RandomTime." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/RandomTime.html.

APA

Wolfram Language. (2022). RandomTime. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/RandomTime.html

BibTeX

@misc{reference.wolfram_2024_randomtime, author="Wolfram Research", title="{RandomTime}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/RandomTime.html}", note=[Accessed: 21-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_randomtime, organization={Wolfram Research}, title={RandomTime}, year={2022}, url={https://reference.wolfram.com/language/ref/RandomTime.html}, note=[Accessed: 21-November-2024 ]}