#!/usr/local/bin/perl # This script was written for www.philforhumanity.com. # If you have any questions, issues, or enhancement requests, please contact us via the website. # Use this script at your own risk. #################################################################################################### # # # This is a Perl script to generate one hundred thousand (100,000) random numbers from 0 through 9 # # inclusively. # # # # Most programming languages are really bad at generating random numbers. # # However, if we set the random number seed to a different value each time that the program is # # executed, then the random numbers will appear to be much more random. # # # #################################################################################################### # Get the timestamp number. This is the old method of generating an unqie random number seed. # my $time = time(); # Get the process id number. This is the new method of generating an unqie random number seed. my $process_id = $$; # Set the random number seed to the process id. srand($process_id); # Set how many random numbers (from 0 to 9) that you want to generate. my $max_numbers = 100000; # Open the output file to save to. open (FH, "> List_of_Random_Generated_Numbers.txt"); # Get and display random numbers. for (my $loop=0 ; $loop < $max_numbers ; $loop++) { # Get random number from 0 to 10 exclusive. Note that this will result with a real (decimal number). $random_number = rand (10); # Only get the first digit of the random number. $first_random_digit = $random_number % 10; # Print random digit to the file. print FH "$first_random_digit"; } # Close output file. close FH; # Exit. exit 0;