อ่าน Naruto 700 แปลไทย, อ่าน One Piece 782 แปลไทย, อ่าน Bleach 622 แปลไทย, อัพเดทข่าวประจำวันและข่าวไอที โหลดเพลง โหลดโปรแกรม คำคมโดนๆ

SMF & Programmer => Programmer => ข้อความที่เริ่มโดย: Admin ที่ กุมภาพันธ์ 21, 2012, 08:43:48 pm

หัวข้อ: สุ่มบัตรประชาชน Perl
เริ่มหัวข้อโดย: Admin ที่ กุมภาพันธ์ 21, 2012, 08:43:48 pm
[mb]

โค๊ด: [Select]

#!/usr/bin/env perl
# Thai ID Number Random original code by AssazziN THD
# Port to Linux by Ron Linix
use Tk;

### ID rand func
sub makeTSSN {
$id[0]=int(rand(8))+1;
$last=$id[0];
foreach $z (2..12) {
   $id[$z-1]=int(rand(9));
   $tmp[$z-1]=$id[$z-1]*(14-$z);
   $last+=$tmp[$z-1];
}
$last=11-($last%11);
if ($last==11) {
   $last=1;
}
elsif ($last==10) {
   $last=0;
}
$key=join('',@id);
$key.=$last;
#return $key;
return "$id[0]-$id[1]$id[2]$id[3]$id[4]-$id[5]$id[6]$id[7]$id[8]$id[9]-$id[10]$id[11]-$last";
}

### GUI
my $id;
my $mw = new MainWindow();
$mw->title("Thai ID Random.");
$mw->Label( -text => 'Thai ID Gen : Linux port by Ron Linix Original from AssazziN THD')->pack;
$entry = $mw->Entry( -textvariable => \$id )->pack;
$mw->Button( -text => 'Generate',
   -command => sub{ $id = &makeTSSN, print $id,"\n",} )->pack;
MainLoop;

[/mb]
Cd - AssazziN THD