Search code examples
randomkdbq-lang

KDB+ / Q unique random values with variable for amount


I am quite new to KDB+ and have a question about generating random numbers.

Lets say I want to create num random unique numbers.

When i use this

q)10?10
q)-10?10

I get 10 random numbers in line 1 and 10 unique random numbers in line 2 (range from 0 to 9)

When I want to introduce a variable like this

q)num:10
q)num?10  / works
q)-num?10 / dont work

The generation of unique randoms does not work.

Whats the correct syntax for this?

Thanks in advance


Solution

  • This will give you num unique numbers between 0 and 9.

    q)(neg num)?10