From: David Polakovic Date: Mon, 1 Apr 2024 18:48:45 +0000 (+0200) Subject: corrected ret & oem part2 subroutines X-Git-Url: https://git.dpolakovic.space/?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=w958-generator corrected ret & oem part2 subroutines --- diff --git a/generate-for b/generate-for index c4eb906..012877a 100644 --- a/generate-for +++ b/generate-for @@ -13,19 +13,13 @@ sub generate95_ret_part1 { return $string; } -# generates 7 digit number of which digit sum is 7 (e.g.: 4001110) +# generates 7 digit number divisible by 7 sub generate95_ret_part2 { - my $sum = shift; - my $string = ""; - - for my $i (1..6) { - my $digit = int(rand($sum + 1)); - $sum -= $digit; - $string .= $digit; - } - $string .= $sum; - - return $string; + my $num; + do { + $num = int(rand(9000000)) + 1000000; + } while ($num % 7 != 0); # Repeat until the number is divisible by 7 + return $num; } # picks random two digit combination from the list @@ -34,17 +28,19 @@ sub generate95_oem_part2 { my $random_index = int(rand(scalar @list)); my $random_value = $list[$random_index]; } -# generates random 7 digit number, starting with "00" + + +# generates random 7 digit number, starting with "00" and divisible by 7 sub generate95_oem_part3 { - my $sum = shift; - my $string = "00"; + my $string = "00"; # Start with "00" - for my $i (3..6) { - my $digit = int(rand($sum + 1)); - $sum -= $digit; - $string .= $digit; + while (1) { + my $number = int(rand(90000)) + 10000; + if ($number % 7 == 0) { + $string .= $number; + last; + } } - $string .= $sum; return $string; } @@ -76,7 +72,7 @@ if (@ARGV == 0) { my $result95_oem = $result95_oem_part1 . $result95_oem_part2 . - "-dpo-" . + "-OEM-" . $result95_oem_part3 . "-" . $result95_oem_part4;