adding random numbers to a list in kdb+ Q programming language

Viewed 206

I am trying to create an empty list that takes integer values.

I have tried a:($['int])

I am trying to add 10 random numbers to the list but the only way i can do it is if i specify the number range(between 1-100) : a:(10?100)

thanks

2 Answers

This is what you could do:

q)/Init empty list of ints
q)a:`int$()
q)/Check what the list looks like
q)a
`int$()
q)/6h means that a is of type list of ints
q)type a
6h

q)/Append 10 random numbers between 0-100 to list
q)a,:10?100
q)a
12 10 1 90 73 90 43 90 84 63i

If you don't want to specify a range you can use:

10?0i

This would generate any positive or negative integer.

Similarly,

10?0Wi

would generate any positive integer

Related