apply database managing class and random pick

Signed-off-by: rei <reiheart@gmail.com>