random.js: Replaced if condition with a try/catch