It's your grep /$rand/ ... Try /^$rand$/, or $_ eq $rand :)
In reply to Re: How much random is rand()? by almut in thread How much random is rand()? by gmoque