refactor code: improve rand_lb