in reply to Re: How do I get my code to not repeat numbers and also sort the numbers
in thread How do I get my code to not repeat numbers and also sort the numbers

I was able to get the code to sort. But I am trying to use grep to take out the repeating numbers. How do I do that? This is what I have below.

for ($i_lottery=0; $i_lottery<$NumberOfTickets; $i_lottery++) { for ($i=0; $i<$NumbersOnTickets; $i++) { $lotto[$i]= int(rand($HighestNumberOnTicket)) + 1; } grep($NumbersOnTickets,@lotto); $NumbersOnTickets=@lotto; @sorted = sort { $a <=> $b } @lotto; print "@sorted"; print "<P>"; }

Replies are listed 'Best First'.
Re^3: Take out repeating numbers with grep
by ikegami (Patriarch) on Jun 10, 2010 at 02:02 UTC
    Won't filtering out duplicates leave you with too few numbers? If that's what you want, here you go:
    my %seen; my @unique = grep !$seen{$_}++, @numbers;

    This is in perlfaq4