Back to Creating Tables

In Memory Tables · Creating Tables · Practice Question

Generate Random Market Data

Sign in to track your progress

Question

Create a table named t with 1000 rows and the following schema:

ColumnType
symsymbol
pricefloat
timetimestamp

Requirements:

  • sym should contain random values chosen from `A `B `C.
  • price should contain random values in the range 100.0 to 200.0.
  • time should 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`C

randomly selects 1000 symbols, with replacement, from `A`B`C. These values form the sym column.

Price Column

The expression:

1000?100.0

generates 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.0

Timestamp Column

The expression:

.z.d+00:00

produces 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*1000000000

calculates the number of nanoseconds in one day.

Therefore:

1000?60*60*24*1000000000

generates 1000 random offsets within the current day.

Adding these offsets to midnight:

(.z.d+00:00)+1000?60*60*24*1000000000

produces random timestamps throughout the day.

Verifying the Result

The schema can be inspected using:

meta t

Result:

c    | t f a
-----| -----
sym  | s
price| f
time | p

showing that:

  • sym is a symbol column (s)
  • price is a float column (f)
  • time is 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.