gpt4 book ai didi

mysql - 播种 SQLite RANDOM()

转载 作者:IT王子 更新时间:2023-10-29 06:23:26 27 4
gpt4 key购买 nike

SQLite 是否支持播种 RANDOM() 的功能与 MySQL 对 RAND() 的处理方式相同?

$query = "SELECT * FROM table ORDER BY RAND(" . date('Ymd') . ") LIMIT 1;";

来自关于 RAND(N) 的 MySQL 手册:

If a constant integer argument N is specified, it is used as the seed value, which produces a repeatable sequence of column values. In the following example, note that the sequences of values produced by RAND(3) is the same both places where it occurs.

如果没有,有没有办法只使用一个查询来归档相同的效果?

最佳答案

看看 sqlite3_randomness()功能:

SQLite contains a high-quality pseudo-random number generator (PRNG) used to select random ROWIDs when inserting new records into a table that already uses the largest possible ROWID. The PRNG is also used for the build-in random() and randomblob() SQL functions.

...

The first time this routine is invoked (either internally or by the application) the PRNG is seeded using randomness obtained from the xRandomness method of the default sqlite3_vfs object. On all subsequent invocations, the pseudo-randomness is generated internally and without recourse to the sqlite3_vfs xRandomness method.

查看这个xRandomness方法的源码,可以看到它是从Unix上的/dev/urandom读取的。在 Windows 上,它只是返回一些时间函数的返回值。因此,看来您唯一的选择就是开始破解 SQLite 源代码。

关于mysql - 播种 SQLite RANDOM(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2171578/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com