# Untitled

By: a guest on Aug 20th, 2012  |  syntax: Perl  |  size: 1.62 KB  |  hits: 21  |  expires: Never
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
1. #!/usr/bin/env perl
2. #==============
3. # Random number generator for Powerball lottery.
4. # toast
5. # A random number generator for playing megabucks plus.
6. # Will Generate 5 random numbers between 1 and 59 and then 1 number
7. # between 1 and 35 for the powerball.
8. # Written and tested under Slackware 13.37
9. #==============================
10.
11. use strict;
12. use warnings;
13.
14. my \$min = 1;
15.
16. # This will generate 10 numbers remove any duplicates, then display 5 numbers.
17. my \$range = 59; # Defines the range of numbers
18.
19. # Generates the numbers
20. my \$number0 = int(rand(\$range)) + \$min;
21. my \$number1 = int(rand(\$range)) + \$min;
22. my \$number2 = int(rand(\$range)) + \$min;
23. my \$number3 = int(rand(\$range)) + \$min;
24. my \$number4 = int(rand(\$range)) + \$min;
25. my \$number5 = int(rand(\$range)) + \$min;
26. my \$number6 = int(rand(\$range)) + \$min;
27. my \$number7 = int(rand(\$range)) + \$min;
28. my \$number8 = int(rand(\$range)) + \$min;
29. my \$number9 = int(rand(\$range)) + \$min;
30.
31. # places the numbers in an array
32. my @picks = (
33.       \$number0,
34.       \$number1,
35.       \$number2,
36.       \$number3,
37.       \$number4,
38.       \$number5,
39.       \$number6,
40.       \$number7,
41.       \$number8,
42.       \$number9
43.    );
44.
45. # Checks the array and removes any duplicates
46. my \$i;
47. my %seen;
48. my @nodupes;
49. foreach \$i (@picks) {
50. push(@nodupes, \$i) unless (\$seen{\$i}++);
51.
52. }
53.
54. # Defines the numbers to be printed
55. @picks=@nodupes;
56. splice @picks, 5, 10;
57.
58. # Generate the number for the Powerball
59. my \$power_range = 35;
60.
61. my \$powerball = int(rand(\$power_range)) + \$min;
62.
63. # Print out the generated numbers.