Aruna Goke wrote:
> I am writing a raffle draw promo using perl and i have the script as below.
>
> what i intend to achieve is to print all the numbers in the array to gui
> screen, clear the screen and display randomly selected one as the winner.
>
> however, I have run my script in the cmd line .. it works fine but I
> need a colorful GUI to do that.
>
> Can someone guide me on where i can get a solution to it?
>
> I have laid my hand on wxperl but unable to print it.
>
>
>
> the code
>
> #!/usr/bin/perl
>
> use warnings;
> use strict;
>
> my @hash = (1010000 .. 1019999);
>
> # I collect a big array from the file turn it to array and select at
> random some x numbers.
> my @testran;
> my ($xy, $xz);
>
> for(1..500){
> $xy = int(rand($#hash-1));
> push @testran, $hash[$xy];
> }
>
> for(1..3){
> print "\t\n";
> print " $_\t" for @testran;
> print "\n\n";
> }
>
> print "\n"x10;
>
> print "\t\t\t THE WINNING NUMBER IS \t";
>
> my $win_id = int(rand(@testran));
> print "$testran[$win_id]\n";
> print "\n\n";
>
It's worth pointing out that your basic algorithm is broken. You start by making
500 random picks from a set of 10,000 ticket numbers, after which there is only
the tiniest chance that you haven't picked the same ticket twice. To select 500
unique numbers use this:
use List::Util qw/shuffle/;
my @hash = (1010000 .. 1019999);
my @testran = (shuffle @hash)[0 .. 499];
(That is apart from my reservations about having an array called @hash :)
HTH,
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/