aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGZNGET FOSS Team <opensource@gznianguan.com>2017-06-21 12:10:33 +0200
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2017-06-21 12:10:33 +0200
commit3fc4c7f0f8c39955971c7590d4833f83e30e2000 (patch)
tree5ae22bd9573b9ae36f2e0c94fedb7a034c77a99a
parentd49ea79aed958d7ac0cab5ef21f63a7d3fc37ebf (diff)
downloadperl-Arctica-Core-3fc4c7f0f8c39955971c7590d4833f83e30e2000.tar.gz
perl-Arctica-Core-3fc4c7f0f8c39955971c7590d4833f83e30e2000.tar.bz2
perl-Arctica-Core-3fc4c7f0f8c39955971c7590d4833f83e30e2000.zip
Add new type 'short_id' to getARandom().
-rw-r--r--lib/Arctica/Core/Basics.pm20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/Arctica/Core/Basics.pm b/lib/Arctica/Core/Basics.pm
index 283b2ae..2112670 100644
--- a/lib/Arctica/Core/Basics.pm
+++ b/lib/Arctica/Core/Basics.pm
@@ -135,6 +135,26 @@ sub genARandom {
}
return "$time$r_string";
+ } elsif ($in_type eq "short_id") {
+ if ($in_length =~ /^(\d{1,})$/) {
+ $in_length = $1;
+ if ($in_length < 4) {
+ $in_length = 4;
+ } elsif ($in_length > 16) {
+ $in_length = 16;
+ }
+ } else {
+ $in_length = 8;
+ }
+ srand();
+ my @p_chars = ('0'..'9','a'..'z','A'..'Z');
+ my $r_lenght = $in_length;
+ my $r_string;
+ for (my $i=0; $i<$r_lenght; $i++) {
+ $r_string .= $p_chars[int(rand($#p_chars + 1))];
+ }
+ return $r_string;
+
} elsif ($in_type eq "key") {
if ($in_length =~ /^(\d{1,})$/) {
$in_length = $1;