Implement random calling of optimized OpenDB with a possible optional env var

- No API signature changes
- genenv is now just called once