在 SQLite 中
The
random()
function returns a pseudo-random integer between -9223372036854775808 and +9223372036854775807.
您可以使用 Select random() % n ;
但这仍然会产生负数。我怎样才能在 SQLite 中只生成正随机数?
最佳答案
使用 ABS()
(绝对值)函数:
SELECT ABS(RANDOM() % N)
注意:
If X is the integer -9223372036854775808 then
abs(X)
throws an integer overflow error since there is no equivalent positive 64-bit two's complement value.
关于sqlite - 在 SQLite 中只生成正随机数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8304204/