1 Replies - 2680 Views - Last Post: 21 April 2010 - 12:35 AM

#1 born2c0de   User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 187
  • View blog
  • Posts: 4,673
  • Joined: 26-November 04

Random Number Generator List

Posted 26 October 2005 - 08:10 AM

Description: A random Number generator list.This script will generate a list of random numbers that are not repeated in the list. Very useful in generating lotto numbers or anything else that you can not have repetitive numbers. ORIGINAL AUTHOR UNKNOWN.
#!/usr/bin/perl -w
    ###############################################
    ## A random Number generator list.
    ## This script will generato a list of
    ## random numbers that are not repeated
    ## in the list. Very useful in generating
    ## lotto numbers or anything else that
    ## you can not have repetitive numbers
    ###############################################
    use strict;
    use integer;
    ########################################
    ## Configuration:
    ## @Numbers = a valid range of numbers
    ## $Limit= a count of how many random
    ##to return. This includes 0, so if
    ##you put 20, 21 numbers will be 
    ##returned in the list.
    ########################################
    my @Numbers = 1..49;
    my $Limit = 20; 
    my @list = ();
    print "n****************************************************n";
    print "***** This is a Random number generator script *****n";
    print "****************************************************nnn";
    for(my $i = 0; $i <= $Limit; $i++) {
    my $intRand = int(rand(@Numbers))+1;
    #########################################
    ## Add the first number to the list, and
    ## then compare all remaining numbers 
    ## with those numbers already in the list
    #########################################
    if ($i == 0) {
    $list[$i] = $intRand;
    }
    else {
    for (my $j = 0; $j<$i; $j++) {
    while ($intRand == $list[$j]) {
    #########################################
    ## The random number has already been 
    ## added to the list. Generate a new
    ## Random number and set the $j counter
    ## to -1 so it starts over to see if the
    ## newly generated number is in the list
    #########################################
    $intRand = int(rand(@Numbers))+1;
    $j = -1;
    }
    #########################################
    ## We just found another random number
    ## that has not been added to the list 
    ## yet, so we are adding it in now.
    #########################################
    $list[$i] = $intRand;
    }
    }
    }
    print "****************************************************n";
    print "** This is the list of ". ($Limit+1) ." random numbers chosenn";
    print "** by the system in the order they were chosenn";
    print "****************************************************nn";
    for (my $i = 0; $i <=$Limit; $i++) {
    print "$list[$i] ";
    }
    print "nnn";
    ##########################################
    ## Now Sort the Numeric list of numbers
    ##########################################
    my @SortedList = sort {$a <=> $b} @list;
    print "****************************************************n";
    print "** This is the Sorted list of ". ($Limit+1) ." randomn";
    print "** numbers chosen by the systemn";
    print "****************************************************nn";
    for (my $i = 0; $i <=$Limit; $i++) {
    print "$SortedList[$i] ";
    }
    print "nnn";



Is This A Good Question/Topic? 0
  • +

Replies To: Random Number Generator List

#2 jherome101391   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 21-April 10

Re: Random Number Generator List

Posted 21 April 2010 - 12:35 AM

,,is this really a source code of lotto?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1