In Memory Tables · Creating Tables · Practice Question
Table with Random Data
Create a Table with Random Values
Question
Create a table named t with 10 rows and the following columns:
| Column | Type | Description |
|---|---|---|
a | symbol | Random symbols made from 3 characters |
b | float | Random floats between 0 and 10 |
c | int | Random integers between 0 and 9 |
Example output:
a b c
--------------
cfl 2.296615 8
bpm 6.919531 1
icj 4.707883 9
ini 6.346716 5
nmo 9.672398 4
ojj 2.306385 6
bjc 9.49975 6
khd 4.39081 1
hjb 5.759051 8
lhk 5.919004 5Solution
t:([] a:10?`3; b:10?10.0; c:10?10i)Explanation
The table is created using q table syntax:
([])Each column is defined inside the table expression.
The first column:
a:10?`3generates 10 random symbols, each made from 3 random characters.
The second column:
b:10?10.0generates 10 random float values between 0 and 10.
The third column:
c:10?10igenerates 10 random int values between 0 and 9.
Putting them together:
t:([] a:10?`3; b:10?10.0; c:10?10i)creates a 10-row table with one symbol column, one float column, and one int column.