Deterministic Random
There’s a function in our codebase called deterministic_rand. It wraps Snowflake’s RAND() — a non-deterministic function that returns a different value every time it’s called — and marks it as deterministic.
This is technically a lie. But it’s a necessary one.
We were building NQL, Narrative’s query language for data operations. At some point we needed randomness — sampling, shuffling, probabilistic filtering. Standard stuff. The problem: certain query operations, like MERGE, refuse to run if any non-deterministic functions are in scope. The database engine sees RAND(), decides the query can’t be safely executed, and bails.
The behavior we wanted was correct. The engine’s model of correctness was just too conservative for our use case. So we wrapped RAND() in a UDF and told the engine: trust me, this is deterministic. The engine believed us. The query ran. The world did not end.
Every sufficiently complex system has moments like this. The type checker that won’t let you express a valid program. The query planner that won’t optimize a safe query. The build system that flags a correct dependency as circular. The gap between “what the model permits” and “what is actually correct” is real, and sometimes the only path through it is a small, deliberate misrepresentation.
This isn’t sloppy engineering. It’s a recognition that formal systems are approximations. They model the world well enough to be useful, but not perfectly enough to cover every case. When your use case falls in the gap, you have two options: change the system (expensive, slow, often impossible) or tell the system what it needs to hear (fast, targeted, gets the job done).
The risk, of course, is that you lie badly. If deterministic_rand were used in a context where true determinism actually mattered — a query that gets replayed, a result that needs to be reproducible — you’d get silent corruption. The lie would compound. That’s the thing about lying to machines: they believe you completely, every time, without skepticism.
So the craft is in knowing when the lie is safe. Understanding the model well enough to know exactly where it’s wrong. Using the escape hatch with precision, not convenience.
deterministic_rand has been in the codebase for years. Every time I see it, I laugh a little. It’s a perfect artifact — a name that is an oxymoron, doing exactly what it says, for exactly the right reasons.
If I ever start a religion, I’m calling it Deterministic Random. The theology is already there: the universe has a plan, it just looks like chaos from your vantage point. Free will is a UDF marked deterministic. The query optimizer argues about predestination.
The sacred text would just be a comment in a file somewhere: // We know. It’s fine. Trust us.