AKZN Notes

Archives for My Lazy and Forgetful Mind

Generate Random Data Function with Mysql

Last Modified on

Function Helper

DROP FUNCTION IF EXISTS generate_fname;
DELIMITER $$
CREATE FUNCTION generate_fname () RETURNS VARCHAR(255)
BEGIN
    RETURN ELT(FLOOR(1 + (RAND() * (50-1))), "Deni","Desi","Dito","Femi","Hafid","Rizki","Utami","Aulia","Tika","Hadi","Bayu","Annisa","Retno","Fajar","Wulandari","Nurul","Rini","Ilham","Kusuma","Rizki","Dinda","Andre","Ari","Maria","Wahyu","Mila","Lia","Kartika","Indra","Eko","Kurniawan","Sari","Ajie","Sri","Tyas","Dian","Lestari","Maya","Ika","Arya","Yudi","Andy","Anthony","Siti","Rio","Sarah","Reza","Andi","Fitri","Nur","Ade","Agus","Tri","Indah","Dian","Putra","Muhammad","Dwi","Jeffrey","Melissa","Eric","Anna","Stephen","Andrew");
END$$

DELIMITER ;

DROP FUNCTION IF EXISTS generate_lname;
DELIMITER $$
CREATE FUNCTION generate_lname () RETURNS VARCHAR(255)
BEGIN
    RETURN ELT(FLOOR(1 + (RAND() * (58-1))), "Bagaskoro","Bakti","Dewangga","Dharma","Danastri","Danurdara","Diajeng","Endaru","Endang","Elok","Erina","Estiana","Gadhing","Ganendra","Gardara","Martin","Gentala","Galih","Ganesh","Gibran","Guinandra","Gumelar","Gunawan","Guntur","Guritno","Gusti","Gahyaka","Gantari","Ihsan","Ismoyono","Indira","Intan","Isthika","Jamal","Janu","Jatmika","Jaya","Jenaka","Jenggala","Jumanta","Jumantara","Kamajaya","Karunia","Kawindra","Kresna","Garini","Gayatri","Gemani","Gemintang","Gempita","Ginanita","Hakim","Halim","Hamdan","Hanafi","Handaru","Hapsari","Hardana","Haribawa");
END$$
DELIMITER ;

Example query

SELECT generate_fname() AS FirstName, generate_fname() AS LastName;
SELECT CONCAT(generate_fname(), ' ' ,generate_lname()) AS nama, 

More random names

DROP function if exists generate_fname;
DELIMITER $$
CREATE FUNCTION generate_fname () RETURNS varchar(255)
BEGIN
    RETURN ELT(FLOOR(1 + (RAND() * (100-1))), "James","Mary","John","Patricia","Robert","Linda","Michael","Barbara","William","Elizabeth","David","Jennifer","Richard","Maria","Charles","Susan","Joseph","Margaret","Thomas","Dorothy","Christopher","Lisa","Daniel","Nancy","Paul","Karen","Mark","Betty","Donald","Helen","George","Sandra","Kenneth","Donna","Steven","Carol","Edward","Ruth","Brian","Sharon","Ronald","Michelle","Anthony","Laura","Kevin","Sarah","Jason","Kimberly","Matthew","Deborah","Gary","Jessica","Timothy","Shirley","Jose","Cynthia","Larry","Angela","Jeffrey","Melissa","Frank","Brenda","Scott","Amy","Eric","Anna","Stephen","Rebecca","Andrew","Virginia","Raymond","Kathleen","Gregory","Pamela","Joshua","Martha","Jerry","Debra","Dennis","Amanda","Walter","Stephanie","Patrick","Carolyn","Peter","Christine","Harold","Marie","Douglas","Janet","Henry","Catherine","Carl","Frances","Arthur","Ann","Ryan","Joyce","Roger","Diane");
END$$

DELIMITER ;

DROP function if exists generate_lname;
DELIMITER $$
CREATE FUNCTION generate_lname () RETURNS varchar(255)
BEGIN
    RETURN ELT(FLOOR(1 + (RAND() * (100-1))), "Smith","Johnson","Williams","Jones","Brown","Davis","Miller","Wilson","Moore","Taylor","Anderson","Thomas","Jackson","White","Harris","Martin","Thompson","Garcia","Martinez","Robinson","Clark","Rodriguez","Lewis","Lee","Walker","Hall","Allen","Young","Hernandez","King","Wright","Lopez","Hill","Scott","Green","Adams","Baker","Gonzalez","Nelson","Carter","Mitchell","Perez","Roberts","Turner","Phillips","Campbell","Parker","Evans","Edwards","Collins","Stewart","Sanchez","Morris","Rogers","Reed","Cook","Morgan","Bell","Murphy","Bailey","Rivera","Cooper","Richardson","Cox","Howard","Ward","Torres","Peterson","Gray","Ramirez","James","Watson","Brooks","Kelly","Sanders","Price","Bennett","Wood","Barnes","Ross","Henderson","Coleman","Jenkins","Perry","Powell","Long","Patterson","Hughes","Flores","Washington","Butler","Simmons","Foster","Gonzales","Bryant","Alexander","Russell","Griffin","Diaz","Hayes");
END$$
DELIMITER ;

select generate_fname() as FirstName, generate_fname() as LastName;

Leave a Reply

Your email address will not be published.