DELIMITER $$ CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`validationCode_beta`(vString VARCHAR(255)) RETURNS int(11) DETERMINISTIC BEGIN DECLARE vSeed DOUBLE DEFAULT 0; DECLARE vCode INT; DECLARE vLength INT; DECLARE vChar INT; SET vLength = length(vString); WHILE vLength > 0 DO SET vChar = MID(vString,vLength,1); SET vSeed = vSeed + ASCII(vChar); SET vLength = vLength - 1; END WHILE; SET vCode = FLOOR(SQRT(vSeed)*1000000) mod 1000; RETURN vCode; END$$ DELIMITER ;