Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.84 KB | None | 0 0
  1. # Функция броска кубиков. Принимает в качестве аргумента строку
  2. # xdn, где "x" количество бросков, "n" количество граней кубика,
  3. # а "d" - разделитель. Возвращает массив результатов бросков.
  4. sub dice_throw {
  5.     my @throw_result;
  6.     my $i = 0;
  7.     my @throw_params = split(/d/, $_[0]);
  8.     while($_[0] =~ /d/g) {
  9.         $i++;
  10.     }
  11.     if ($i != 1) {
  12.         error(3);
  13.     }
  14.     for ($i = 0; $i <= 1; $i++) {
  15.         if (! $throw_params[$i] || $throw_params[$i] !~ /^\d+$/) {
  16.             error(3);
  17.         }
  18.     }
  19.     $#throw_result = $throw_params[0]-1;
  20.     for ($i = 0; $i <= $#throw_result; $i++) {
  21.         $throw_result[$i] = int(rand($throw_params[1]))+1;
  22.     }
  23.     return @throw_result;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement