In Memory Tables · Creating Tables · Practice Question
Generate Random Market Data
Question
Create a table named t with 1000 rows and the following schema:
| Column | Type |
|---|---|
sym | symbol |
price | float |
time | timestamp |
Requirements:
symshould contain random values chosen from`A `B `C.priceshould contain random values in the range100.0to200.0.timeshould contain random timestamps within the current day (UTC).
Solution
t:([]
sym:1000?`A`B`C;
price:100.0+1000?100.0;
time:(.z.d+00:00)+1000?60*60*24*1000000000
)Example output:
sym price time
-----------------------------------------------
A 142.3175 2025.12.05D14:23:17.123456789
C 198.4521 2025.12.05D08:51:42.987654321
B 115.9084 2025.12.05D19:07:11.456789123
...Explanation
The table is created using standard table syntax, ([] col1:...; col2:...).
Symbol Column
The expression:
1000?`A`B`Crandomly selects 1000 symbols, with replacement, from `A`B`C. These values form the sym column.
Price Column
The expression:
1000?100.0generates 1000 random floats from 0.0 up to (but not including) 100.0. Adding 100.0 shifts the range to 100.0–200.0, giving:
price:100.0+1000?100.0Timestamp Column
The expression:
.z.d+00:00produces midnight of the current day as a timestamp — for example 2025.12.05D00:00:00.000000000. (.z.d is the current date in UTC; use .z.D for local time.)
The expression:
60*60*24*1000000000calculates the number of nanoseconds in one day.
Therefore:
1000?60*60*24*1000000000generates 1000 random offsets within the current day.
Adding these offsets to midnight:
(.z.d+00:00)+1000?60*60*24*1000000000produces random timestamps throughout the day.
Verifying the Result
The schema can be inspected using:
meta tResult:
c | t f a
-----| -----
sym | s
price| f
time | pshowing that:
symis a symbol column (s)priceis a float column (f)timeis a timestamp column (p)
Summary
This question demonstrates how to generate realistic market-style data using:
- Random symbol selection with
? - Random float generation
- Random timestamp generation using nanosecond offsets from the start of the current day
The resulting table is useful for testing qSQL queries, joins, aggregations, and time-series operations.