Guest User

Untitled

a guest
Jan 26th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.04 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2. use DBI;
  3.  
  4.  
  5. sub GetRandomFreeLocation
  6. {
  7.     $db="weekly";
  8.     $host="localhost";
  9.     $user="user";
  10.     $password="password";
  11.  
  12.     my $restrict = $_[0];
  13.     my $dbh = DBI->connect ("DBI:mysql:database=$db:host=$host", $user, $password) or die $dbh->errstr;
  14.     my $data = ( "SELECT value from quest_globals where name like 'halloween_ratter_%' order by CAST(`value` AS SIGNED)");
  15.     my $sth = $dbh->prepare($data);
  16.     $sth->execute() or die $dbh->errstr;
  17.  
  18.     while(my $ref = $sth->fetchrow_arrayref) {
  19.         push @used_values, $ref->[0];
  20.     }
  21.     $dbh->disconnect();
  22.  
  23.     if($restrict == 1){
  24.         @all_values = (0,3,4,6,7,8,9,10,12,13,14,16,17,20,21,22,23,24,25,27,29,30,31,32,33,34,36,37,38,40);
  25.     }
  26.     else {
  27.         @all_values = (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40);
  28.     }
  29.  
  30.     %used_values = map {$_, 1} @used_values;
  31.     @free_values = grep {!$used_values {$_}} @all_values;
  32.     $random_value = join("", @free_values[ map { rand @free_values } ( 1 .. 1 ) ]);
  33.    
  34.     return $random_value;
  35. }
Add Comment
Please, Sign In to add comment