mardi 8 mai 2018

Peewee: getting random records, with an specific seed

The peewee documentation explains how to get a random record from a table:

Table.select().order_by(fn.Random())

however, I want to reproduce the result for a series of tests.

I've checked that in SQL exists the function setseed, but it does not work, if I use it like this:

Table.select(fn.setseed(1)).order_by(fn.Random())

returning the error:

peewee.OperationalError: no such function: setseed

An additional workaround would be to use the native random module of python and select a random id of the table. Nevertheless, I wonder if it is possible to set the seed.

I am using Python 2.7, Peewee 2.10 and SQLite.




Aucun commentaire:

Enregistrer un commentaire