rand: improve performance