peewee documentation解释了如何从表中获取随机记录:
Table.select().order_by(fn.Random())
但是,我想重现一系列测试的结果。
我已经检查过SQL中存在函数 setseed ,但如果我像这样使用它,它就不起作用了:
Table.select(fn.setseed(1)).order_by(fn.Random())
返回错误:
peewee.OperationalError:没有这样的功能:setseed
另一种解决方法是使用python的本机随机模块并选择表的随机ID。 不过,我想知道是否有可能设定种子。
我使用的是Python 2.7,Peewee 2.10和SQLite。