cancel
Showing results for 
Search instead for 
Did you mean: 

Bug? rand with find

Naoki_Yatsu
New Contributor
Rand with find(?) sometimes returns strange number.
Is this a bug?

-----------------------------
KDB+ 3.3 2015.07.09 Copyright (C) 1993-2015 Kx Systems
l32/ 4()core

q)10?rand 10
2 1 2 1 2 3 2 5 4 7
...
q)10?rand 10
6299546977983373652 2157301088332608031 -7209837269872637184 -453213953909620..

3 REPLIES 3

Tom_Martin
New Contributor
New Contributor
It's what you get when you use ? with 0 on the RHS

q)10?0
-6739119069145492435 4254529079255828354 8099614742952382528 -7528108271820962578 717681689843314..

Not sure if it's documented anywhere but it's always had this behaviour.

rahul_asati04
Contributor


 r:rand X

If X is an atom 0, it returns a random value of the same type in the range of that type.
If X is a positive number, it returns a random number of the same type in the range [0,X)

Naoki_Yatsu
New Contributor
Thank you, Tom, RAHUL.
I understand. In this case, rand is unnecessary, 10?10 is enough.