Random, min and max function (snippet)