Let me first note that the 0D...
syntax is not specific to the rand operator. The prefix 0D
is needed when a type of a literal kdb would infer without it would be different from what you intended. For example:
q)type 08:09:10.123 / time
-19h
q)type 0D08:09:10.123 / timespan
-16h
The prefix is optional when a type can be inferred unambiguously; in case of timespan literals it's sufficient to supply more than 4 digits after the dot when using the hh:mm:ss.nnnnnnnnn
notation:
q)type 08:09:10.123 / time
-19h
q)type 08:09:10.1234 / still time
-19h
q)type 08:09:10.12345 / timespan
-16h
The 0D
notation is very handy when you need a timespan value but don't want to specify all the details down to nanoseconds. I think you will agree that 0D00:01
(1 minute) is easier to type and read than 00:01:00.000000000
.
Going back to your question, 0D0
is just a zero-valued timespan, the same as 00:00:00.00000000
. However, ?
treats it as if 1D0
(or 0D24:00:00.000000000
) was passed. I didn't see it documented anywhere on code.kx.com but if you think about it you'll agree that generating a timespan in the range [0; 24h) is such a common case that it definitely deserves a shortcut. And there you have it!