In Memory Tables · Updating Tables · Practice Question
Add a Column of Random Booleans
Question
Given a table t, add a new column d that contains a random boolean for every row.
For example:
t:([] sym:`A`B`C; price:120.5 151.2 175.0)Solution
update d:(count t)?0b from `tExplanation
(count t)?0b generates one random boolean per row of t — count t gives the number of rows needed, and ? with a boolean atom (0b) on the right draws that many random 0b/1b values.
update d:... from tadds the result as a new columnd. Passing the table name as a symbol (`` t ``) makes the update happen in place, rather than returning a new table that would need to be reassigned.