[NTLUG:Discuss] Bash script question

brad angelcyk bradangelcyk at gmail.com
Wed Jan 19 15:50:59 CST 2005


====================
#!/usr/bin/perl

open (FILE, "list");
my @list = <FILE>;
close (FILE);

my $temp;
for (my $i = 0; $i < 40; $i++)
{
  $temp = rand(scalar @list);
  print $list[$temp];
  delete $list[$temp];
}
====================

Yes, I realize that it's not in bash.  Just trying to give you some
options.  :-)

Brad



On Wed, 19 Jan 2005 14:09:47 -0600, Lance Simmons <lance at lsimmons.net> wrote:
> Let's say I have 100 names in a file.  I want to randomly select a name
> from the file, add it to a list, and repeat that process 40 times.  The
> result of the process should be a list of 40 names in random order, some
> of which may repeat in the list.
> 
> What I've been doing up to now is putting the 100 names in random order
> and then taking the first 40 lines of the resulting list.  But I want to
> have the possibility of a name appearing multiple times on the same
> list.
> 
> Does anyone have any suggestions?
> 
> --
> Lance Simmons
> 
> _______________________________________________
> https://ntlug.org/mailman/listinfo/discuss
>



More information about the Discuss mailing list