The rand has gained for a second day as renewed optimism over a Greece deal halted an emerging market sell-off that had pushed the local unit to four-week lows.