changed random funtion