Refactoring probability distribution code (don't want to take a dependency on old probabilistic-lua, so I'll just keep importing this as it seems necessary).