replaced random() with rand(), the former is not standard