fix bug of template and rand() problem