Use more idiomatic CS for optionally removing element, minor cleanup for
rand functions