Replicated original myrand() logic; min/max should indeed be swapped if min is larger than max.