Skip to content
Jaskirat Rajasansir edited this page Dec 2, 2022 · 2 revisions

Random Data Generator

This library provides some helper objects and functions when generating random data

Objects

.rand.types / .rand.charTypes

Provides some sensible defaults for every supported type for use with rand or ? to limit the random values.

Type Value
Boolean (1b) 0b
GUID (2b) 0Ng
Byte (4b) 0x0
Short (5h) 256h
Integer (6h) 10000i
Long (7h) 1000000j
Real (8h) 100e
Float (9h) 1000f
Char (10h) .Q.a
Symbol (11h) `4
Timestamp (12h) 2030.01.01D00:00:00.000000000
Month (13h) 2030.01m
Date (14h) 2030.01.01
Datetime (15h) 2030.01.01T00:00:00.000
Timespan (16h) 0D00:00:00.000000000
Minute (17h) 00:00
Second (18h) 00:00:00
Time (19h) 00:00:00.000

Both objects are dictionaries, with the keys of .rand.types being the list type short and .rand.charTypes the character type.

Functions

.rand.generate[schema; rows]

Populates a specified table schema with the specified number of rows.

q) schema:flip `time`sym`price`vol!"PSFJ"$\:()

q) .rand.generate[schema; 10]
2021.11.02 13:08:41.430 INFO  pid-516 jas 0 [./src/rand.q:.rand.generate(18):13] Generating random data [ Schema Cols: time, sym, price, vol ] [ Rows: 10 ] [ Seed: -314159 ]
time                          sym  price    vol
--------------------------------------------------
2011.10.13D18:44:03.983405824 enfe 470.7883 796968
2015.07.07D06:49:39.871666432 plho 634.6716 776408
2015.06.25D02:31:12.372677952 nnil 967.2398 974541
2012.03.14D05:25:45.917840320 glch 230.6385 584094
2005.05.05D10:37:47.927053568 gkpm 949.975  946833
2009.01.19D19:41:18.876502816 bghg 439.081  766842
2023.07.21D09:24:03.543890176 ifna 575.9051 981627
2016.01.16D08:21:01.578606080 fohf 591.9004 987244
2021.05.03D00:27:14.582403328 kdjb 848.1567 323212
2012.05.07D06:42:44.194943040 eegn 389.056  710722

.rand.dr.getBytes[bNum]

Provides access to a random number of bytes from /dev/random.

q) .rand.dr.getBytes 10
0x0e6148c8eae376a1d908

By default, a handle to /dev/random is opened and closed for every read. If reading data frequently, set .rand.cfg.keepDevRandomOpen:1b.

.rand.dr.short / .rand.dr.int / .rand.dr.long / .rand.dr.guid

Random object generators based on data read from /dev/random.

q) .rand.dr.short[]
-17717h

q) .rand.dr.int[]
977804865i

q) .rand.dr.long[]
5598617476672869545

q) .rand.dr.guid[]
7c6ee1e6-4e39-6940-9319-a167f7c8fbf5
Clone this wiki locally