From 3fc4c7f0f8c39955971c7590d4833f83e30e2000 Mon Sep 17 00:00:00 2001 From: GZNGET FOSS Team Date: Wed, 21 Jun 2017 12:10:33 +0200 Subject: Add new type 'short_id' to getARandom(). --- lib/Arctica/Core/Basics.pm | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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; -- cgit v1.2.3