CREATE OR REPLACE FUNCTION next_file_number() RETURNS INTEGER AS '
 DECLARE
  new_id INTEGER;
 BEGIN
  LOOP
    SELECT (((((nextval(''filenumber_seq''::regclass))::numeric + (17545393)::numeric) ^ (127)::numeric) % (899999963)::numeric))::integer + 100000000 INTO STRICT new_id;
    PERFORM id FROM file WHERE id = new_id;
    IF NOT FOUND THEN
      EXIT;
    END IF;
  END LOOP;
  RETURN new_id;
 END;
' LANGUAGE plpgsql;


