better rand.end handling