Skip to content

Instantly share code, notes, and snippets.

@hideki-a
Created December 2, 2015 04:47
Show Gist options
  • Select an option

  • Save hideki-a/9cd97585fb10148b26d4 to your computer and use it in GitHub Desktop.

Select an option

Save hideki-a/9cd97585fb10148b26d4 to your computer and use it in GitHub Desktop.
指定の範囲内で乱数を発生させるプラグイン
id: SetRandomNumVar
name: Set Random Number Variable Plugin
version: 1.0
author_name: Hideki Abe
author_link: https://www.anothersky.pw/
tags:
function:
SetRandomNumVar:
handler: >
sub {
my($ctx, $args) = @_;
my $min = $args->{ range }->[0];
my $max = $args->{ range }->[1];
# http://perl.wansdream.net/article/114897420.html
my $ret = int( ( rand() * ( $max - $min + 1 ) ) + $min );
$ctx->var( $args->{ name }, $ret );
}
<$mt:SetRandomNumVar name="tmp.random_num" range="100","199"$>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment