I did not find any answer in the doc so I ask you for help. I want to generate a random response from my database. To be reproducible, I set the seed and call a simple query this way:
func.setseed(0)
session.query(MyModel.id).order_by(func.random()).first() # --> returns 324
func.setseed(0)
session.query(MyModel.id).order_by(func.random()).first() # --> returns 736
As you can see, even after resetting the seed, the result is still different. However, I found a way to fix it, but I dont understand why:
func.setseed(0)
session.query(MyModel.id).order_by(func.random(0.1)).first() # --> returns 547
func.setseed(0)
session.query(MyModel.id).order_by(func.random(0.1)).first() # --> returns 547
What does the func.random argument mean ?
func.setseed(0)? In your example you don't.func.setseed(0)just creates a function expression object. It is rendered to suitable SQL when compiled and executed as a part of a query.