r570 - general/libdata-random-perl/trunk
Tobias Grimm
pkg-vdr-dvb-changes@lists.alioth.debian.org
Sun, 22 May 2005 09:30:38 +0000
Author: tiber-guest
Date: 2005-05-22 09:30:37 +0000 (Sun, 22 May 2005)
New Revision: 570
Removed:
general/libdata-random-perl/trunk/Changes
general/libdata-random-perl/trunk/MANIFEST
general/libdata-random-perl/trunk/Makefile.PL
general/libdata-random-perl/trunk/README
general/libdata-random-perl/trunk/README.linux.words
general/libdata-random-perl/trunk/README2.linux.words
general/libdata-random-perl/trunk/Random.pm
Log:
switch to mergeWithUpstream
Deleted: general/libdata-random-perl/trunk/Changes
===================================================================
--- general/libdata-random-perl/trunk/Changes 2005-05-22 09:28:10 UTC (rev 569)
+++ general/libdata-random-perl/trunk/Changes 2005-05-22 09:30:37 UTC (rev 570)
@@ -1,35 +0,0 @@
-Revision history for Data::Random.
-
-0.05 Thu Feb 20 2003
- - added default wordlist (copy of linux.words)
- - fixed tests again so they don't fail if Date::Calc or
- GD are not installed
-
-0.04 Tue Feb 26 2002
- - removed false dependency on Perl 5.005_62
- - only load Data::Random::WordList when needed
- (Thanks to Mark Stosberg)
- - fixed tests so they skip appropriate tests if Date::Calc or
- GD are not installed
-
-0.03 Mon Aug 20 2001
- - added rand_image()
-
- - used Carp::cluck() and returned undef on errors instead of
- calling die, thus making it a little more friendly
-
-0.02 Wed May 30 2001
- - correctly made "shuffle" flag default to 1 for rand_words(),
- rand_chars() and rand_set() (Thanks to David Sarno)
-
- - fixed bug where rand_words() would sometimes return less words
- than what's specified in "min" (Thanks to David Sarno)
-
- - allowed results of rand_set() to be unshuffled
-
- - added a plethora of tests (how's one supposed to
- accurately the test validity of random data anyway?)
-
-0.01 Tue Oct 31 2000
- - original version
-
Deleted: general/libdata-random-perl/trunk/MANIFEST
===================================================================
--- general/libdata-random-perl/trunk/MANIFEST 2005-05-22 09:28:10 UTC (rev 569)
+++ general/libdata-random-perl/trunk/MANIFEST 2005-05-22 09:30:37 UTC (rev 570)
@@ -1,17 +0,0 @@
-Changes
-MANIFEST
-README
-README.linux.words
-README2.linux.words
-Makefile.PL
-Random.pm
-Random/WordList.pm
-Random/dict
-t/rand_chars.t
-t/rand_date.t
-t/rand_datetime.t
-t/rand_enum.t
-t/rand_set.t
-t/rand_time.t
-t/rand_words.t
-t/rand_image.t
Deleted: general/libdata-random-perl/trunk/Makefile.PL
===================================================================
--- general/libdata-random-perl/trunk/Makefile.PL 2005-05-22 09:28:10 UTC (rev 569)
+++ general/libdata-random-perl/trunk/Makefile.PL 2005-05-22 09:30:37 UTC (rev 570)
@@ -1,8 +0,0 @@
-use ExtUtils::MakeMaker;
-
-WriteMakefile(
- 'NAME' => 'Data::Random',
- 'VERSION_FROM' => 'Random.pm', # finds $VERSION
- 'PMLIBDIRS' => ['Random'],
- 'PREREQ_PM' => {},
-);
Deleted: general/libdata-random-perl/trunk/README
===================================================================
--- general/libdata-random-perl/trunk/README 2005-05-22 09:28:10 UTC (rev 569)
+++ general/libdata-random-perl/trunk/README 2005-05-22 09:30:37 UTC (rev 570)
@@ -1,16 +0,0 @@
-This is the README file for Data::Random, a Perl module for generating random data. You might find it helpful mostly in test programs to easily generate pseudo-realistic distributions of data.
-
-INSTALLATION:
-
-The standard perl module install process:
-
-perl Makefile.PL
-make
-make test (optional)
-make install
-
-The module also uses Date::Calc for rand_date() and rand_datetime(), and GD for rand_image() (both available on CPAN)
-
---
-
-Adekunle Olonoh <koolade@users.sourceforge.net>
Deleted: general/libdata-random-perl/trunk/README.linux.words
===================================================================
--- general/libdata-random-perl/trunk/README.linux.words 2005-05-22 09:28:10 UTC (rev 569)
+++ general/libdata-random-perl/trunk/README.linux.words 2005-05-22 09:30:37 UTC (rev 570)
@@ -1,209 +0,0 @@
-#!/bin/sh -xe
-# README.linux.words - file used to create linux.words
-# Created: Wed Mar 10 09:12:49 1993 by faith@cs.unc.edu (Rik Faith)
-# Revised: Sat Mar 13 17:02:08 1993 by faith@cs.unc.edu
-#
-# Care was taken to be sure that the linux.words list was free of
-# copyright. This makes linux.words a suitable /usr/dict/words
-# replacement for the Linux community.
-#
-# Since the majority of the words are from Tanenbaum's minix.dict file,
-# the notice from Barry Brachman, included below, should accompany any
-# redistribution of this list.
-
-# Here is a detailed explaination of how I created the linux.words file.
-#
-# This README.words file is actually a shell script that you can use to
-# recreate the linux.words file from original sources.
-#
-# First, I started with minix.dict
-# from cs.ubc.ca:/pub/local/src/sp-1.5/wordlists-1.0.tar.Z
-#
-# The following is from the NOTES file in wordlists-1.0.tar.Z:
-
-# NOTES> These word lists were collected by Barry Brachman
-# NOTES> <brachman@cs.ubc.ca> at the University of British Columbia. They
-# NOTES> may be freely distributed as long as this notice accompanies them.
-# NOTES>
-# NOTES> ==================================================================
-# NOTES> Info for minix.dict:
-# NOTES>
-# NOTES> Article 1997 of comp.os.minix:
-# NOTES> From: ast@botter.UUCP
-# NOTES> Subject: A spelling checker for MINIX
-# NOTES> Date: 6 Jan 88 22:28:22 GMT
-# NOTES> Reply-To: ast@cs.vu.nl (Andy Tanenbaum)
-# NOTES> Organization: VU Informatica, Amsterdam
-# NOTES>
-# NOTES> This dictionary is NOT based on the UNIX dictionary so it is free
-# NOTES> of AT&T copyright. I built the dictionary from three sources.
-# NOTES> First, I started by sorting and uniq'ing some public domain
-# NOTES> dictionaries. Second, as some of you probably know, I have
-# NOTES> written somewhere between 3 and 6 books (depending on precisely
-# NOTES> what you count) and an additional 50 published papers on operating
-# NOTES> systems, networks, compilers, languages, etc. This data base,
-# NOTES> which is online, is nonnegligible :-) Finally, I added a number of
-# NOTES> words that I thought ought to be in the dictionary including all
-# NOTES> the U.S. states, all the European and some other major countries,
-# NOTES> principal U.S. and world cities, and a bunch of technical terms.
-# NOTES> I don't want my spelling checker to barf on arpanet, diskless,
-# NOTES> modem, login, internetwork, subdirectory, superuser, vlsi, or
-# NOTES> winchester just because Webster wouldn't approve of them. All in
-# NOTES> all, the dictionary is over 40,000 words. If you have any
-# NOTES> suggestions for additions or deletions, please post them. But
-# NOTES> please be sure you are not infringing on anyone's copyright in
-# NOTES> doing so.
-# NOTES>
-# NOTES> Andy Tanenbaum (ast@cs.vu.nl)
-
-# The main problem with minix.dict is that many proper names are not
-# capitalized. So, I got english.tar.Z from ftp.uu.net:/doc/dictionaries,
-# which is a mirror of nic.funet.fi:/pub/unix/security/dictionaries.
-#
-# Here is part of the README file for english.tar.Z:
-
-# README>
-# README> FILE: english.words
-# README> VERSION: DEC-SRC-92-04-05
-# README>
-# README> EDITOR
-# README>
-# README> Jorge Stolfi <stolfi@src.dec.com>
-# README> DEC Systems Research Center
-# README>
-# README> AUTHORS OF ORIGIONAL WORDLISTS
-# README>
-# README> Andy Tanenbaum <ast@cs.vu.nl>
-# README> Barry Brachman <brachman@cs.ubc.ca>
-# README> Geoff Kuenning <geoff@itcorp.com>
-# README> Henk Smit <henk@cs.vu.nl>
-# README> Walt Buehring <buehring%ti-csl@csnet-relay>
-#
-# [stuff seleted]
-#
-# README> AUXILIARY LISTS
-# README>
-# README> In the same directory as englis.words there are a few
-# README> complementary word lists, all derived from the same sources
-# README> [1--8] as the main list:
-# README>
-# README> english.names
-# README>
-# README> A list of common English proper names and their derivatives.
-# README> The list includes: person names ("John", "Abigail",
-# README> "Barrymore"); countries, nations, and cities ("Germany",
-# README> "Gypsies", "Moscow"); historical, biblical and mythological
-# README> figures ("Columbus", "Isaiah", "Ulysses"); important
-# README> trademarked products ("Xerox", "Teflon"); biological genera
-# README> ("Aerobacter"); and some of their derivatives ("Germans",
-# README> "Xeroxed", "Newtonian").
-# README>
-# README> misc.names
-# README>
-# README> A list of foreign-sounding names of persons and places
-# README> ("Antonio", "Albuquerque", "Balzac", "Stravinski"), extracted
-# README> from the lists [1--8]. (The distinction betweeen
-# README> "English-sounding" and "foreign-sounding" is of course rather
-# README> arbitrary).
-# README>
-# README> org.names
-# README>
-# README> A short lists names of corporations and other institutions
-# README> ("Pepsico", "Amtrak", "Medicare"), and a few derivatives.
-# README>
-# README> The file also includes some initialisms --- acronyms and
-# README> abbreviations that are generally pronounced as words rather
-# README> than spelled out ("NASA", "UNESCO").
-# README>
-# README> english.abbrs
-# README>
-# README> A list of common abbreviations ("etc.", "Dr.", "Wed."),
-# README> acronyms ("A&M", "CPU", "IEEE"), and measurement symbols
-# README> ("ft", "cm", "ns", "kHz").
-# README>
-# README> english.trash
-# README>
-# README> A list of words from the original wordlists
-# README> that I decided were either wrong or unsuitable for inclusion
-# README> in the file english.words or any of the other auxiliary
-# README> lists. It includes
-# README>
-# README> typos ("accupy", "aquariia", "automatontons")
-# README> spelling errors ("abcissa", "alleviater", "analagous")
-# README> bogus derived forms ("homeown", "unfavorablies", "catched")
-# README> uncapitalized proper names ("afghanistan",
-# README> "algol", "decnet")
-# README> uncapitalized acronyms ("apl", "ccw", "ibm")
-# README> unpunctuated abbreviations ("amp", "approx", "etc")
-# README> British spellings ("advertize", "archaeology")
-# README> archaic words ("bedight")
-# README> rare variants ("babirousa")
-# README> unassimilated foreign words ("bambino", "oui", "caballero")
-# README> mis-hyphenated compounds ("babylike", "backarrows")
-# README> computer keywords and slang ("lconvert", "noecho", "prog")
-# README>
-# README> (I apologize for excluding British spellings. I should have
-# README> split the list in three sublists--- common English, British,
-# README> American---as ispell does. But there are only so many hours
-# README> in a day...)
-# README>
-# README> english.maybe
-# README>
-# README> A list of about 5,000 lowercase words from the "mts.dict"
-# README> wordlist [6] that weren't included in english.words.
-# README>
-# README> This list seems to include lots of "trash", like
-# README> uncapitalized proper names and weird words. It would
-# README> take me several days to sort this mess, so I decided to
-# README> leave it as a separate file. Use at your own risk...
-#
-# [stuff deleted]
-#
-# README> (NON-)COPYRIGHT STATUS
-# README>
-# README> To the best of my knowledge, all the files I used to build these
-# README> wordlists were available for public distribution and use, at least
-# README> for non-commercial purposes. I have confirmed this assumption with
-# README> the authors of the lists, whenever they were known.
-# README>
-# README> Therefore, it is safe to assume that the wordlists in this
-# README> package can also be freely copied, distributed, modified, and
-# README> used for personal, educational, and research purposes. (Use of
-# README> these files in commercial products may require written
-# README> permission from DEC and/or the authors of the original lists.)
-# README>
-# README> Whenever you distribute any of these wordlists, please distribute
-# README> also the accompanying README file. If you distribute a modified
-# README> copy of one of these wordlists, please include the original README
-# README> file with a note explaining your modifications. Your users will
-# README> surely appreciate that.
-# README>
-# README> (NO-)WARRANTY DISCLAIMER
-# README>
-# README> These files, like the original wordlists on which they are
-# README> based, are still very incomplete, uneven, and inconsitent, and
-# README> probably contain many errors. They are offered "as is" without
-# README> any warranty of correctness or fitness for any particular
-# README> purpose. Neither I nor my employer can be held responsible for
-# README> any losses or damages that may result from their use.
-
-# subtract english.trash
-cat minix.dict english.trash english.trash | sort | uniq -u > dict.1
-# subtract english.maybe
-cat dict.1 english.maybe english.maybe | sort | uniq -u > dict.2
-
-# build subtraction list of proper names and abbreviations
-cat english.names misc.names org.names computer.names english.abbrs > sub.1
-tr 'A-Z' 'a-z' < sub.1 | sort | uniq -u > sub.2
-
-# subtract proper names with incorrect capitalization
-cat dict.2 sub.2 sub.2 | sort | uniq -u > dict.3
-
-# build proper name list without possessives
-cat english.names misc.names org.names computer.names | fgrep -v \'s > names.1
-
-# add in proper names (use sort twice to get uppercase before lowercase)
-cat dict.3 names.1 | sort | sort -df | uniq > linux.words
-
-# clean up
-rm dict.[123] sub.[12] names.1
Deleted: general/libdata-random-perl/trunk/README2.linux.words
===================================================================
--- general/libdata-random-perl/trunk/README2.linux.words 2005-05-22 09:28:10 UTC (rev 569)
+++ general/libdata-random-perl/trunk/README2.linux.words 2005-05-22 09:30:37 UTC (rev 570)
@@ -1,29 +0,0 @@
-#!/bin/sh -xe
-# README2.linux.words - second file used to create linux.words
-# Created: Sun Oct 10 18:50:53 1993 by faith@cs.unc.edu (Rik Faith)
-# Revised: Sun Oct 10 21:26:01 1993 by faith@cs.unc.edu
-#
-
-# As noted in README.linux.words, extreme care was taken to be sure that
-# the linux.words list was free of copyright. This was done so that
-# linux.words would be a suitable /usr/dict/words replacement for the Linux
-# community. After the initial release of linux.words, Greg Alt
-# (galt@asylum.cs.utah.edu) and Josh Richardson (josh@gatelink.com) sent me
-# several short lists of words that were not in my original list. They
-# obtained these lists by analyzing FAQs and online text material,
-# including the Federalist Papers. The results were manually analyzed by
-# them before sending the lists to me. In addition, I removed some words
-# which were not listed in The American Heritage Dictionary (Second College
-# Edition, Houghton Mifflin Co., 1991). This method of obtaining words
-# (from documents, not from word lists) is also "safe" from the copyright
-# standpoint. Therefore, I am merging these lists in with (version 1) of
-# linux.words to create the second version of linux.words.
-
-# move version 1 list
-mv linux.words dict.4
-
-# add in proper names (use sort twice to get uppercase before lowercase)
-cat dict.4 extra.words | sort | sort -df | uniq > linux.words
-
-# clean up
-rm dict.4
Deleted: general/libdata-random-perl/trunk/Random.pm
===================================================================
--- general/libdata-random-perl/trunk/Random.pm 2005-05-22 09:28:10 UTC (rev 569)
+++ general/libdata-random-perl/trunk/Random.pm 2005-05-22 09:30:37 UTC (rev 570)
@@ -1,850 +0,0 @@
-################################################################################
-# Data::Random
-#
-# A module used to generate random data.
-################################################################################
-
-package Data::Random;
-
-################################################################################
-# - Modules and Libraries
-################################################################################
-#require 5.005_62;
-
-use lib qw(..);
-use Carp qw(cluck);
-
-#use Data::Random::WordList;
-
-require Exporter;
-
-################################################################################
-# - Global Constants and Variables
-################################################################################
-use vars qw(
- @ISA
- %EXPORT_TAGS
- @EXPORT_OK
- @EXPORT
-);
-
-@ISA = qw(Exporter);
-
-%EXPORT_TAGS = (
- 'all' => [
- qw(
- rand_words
- rand_chars
- rand_set
- rand_enum
- rand_date
- rand_time
- rand_datetime
- rand_image
- )
- ]
-);
-
-@EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
-@EXPORT = qw();
-
-$Data::Random::VERSION = '0.05';
-
-################################################################################
-# - Subroutines
-################################################################################
-
-################################################################################
-# rand_words()
-################################################################################
-sub rand_words {
-
- # Get the options hash
- my %options = @_;
-
- # Initialize max and min vars
- $options{'min'} ||= 1;
- $options{'max'} ||= 1;
-
- # Initialize the wordlist param
- $options{'wordlist'} ||= '';
-
- # Make sure the max and min vars are OK
- cluck('min value cannot be larger than max value') && return
- if $options{'min'} > $options{'max'};
- cluck('min value must be a positive integer') && return
- if $options{'min'} < 0 || $options{'min'} != int( $options{'min'} );
- cluck('max value must be a positive integer') && return
- if $options{'max'} < 0 || $options{'max'} != int( $options{'max'} );
-
- # Initialize the size var
- $options{'size'} ||=
- int( rand( $options{'max'} - $options{'min'} + 1 ) ) + $options{'min'};
-
- # Make sure the size var is OK
- cluck('size value must be a positive integer') && return
- if $options{'size'} < 0 || $options{'size'} != int( $options{'size'} );
-
- # Initialize the shuffle flag
- $options{'shuffle'} =
- exists( $options{'shuffle'} ) ? $options{'shuffle'} : 1;
-
- my $wl;
- my $close_wl = 1;
-
- # Check for a pre-existing wordlist object
- if ( ref( $options{'wordlist'} ) ) {
- $wl = $options{'wordlist'};
- $close_wl = 0;
- }
- else {
- require Data::Random::WordList;
-
- # Create a new wordlist object
- $wl = new Data::Random::WordList( wordlist => $options{'wordlist'} );
- }
-
- # Get the random words
- my $rand_words = $wl->get_words( $options{'size'} );
-
- # Close the word list
- $wl->close() if $close_wl;
-
- # Shuffle the words around
- shuffle($rand_words) if $options{'shuffle'};
-
-# Return an array or an array reference, depending on the context in which the sub was called
- if ( wantarray() ) {
- return @$rand_words;
- }
- else {
- return $rand_words;
- }
-}
-
-################################################################################
-# rand_chars()
-################################################################################
-sub rand_chars {
-
- # Get the options hash
- my %options = @_;
-
- # Build named character sets if one wasn't supplied
- if ( ref( $options{'set'} ) ne 'ARRAY' ) {
- my @charset = ();
-
- if ( $options{'set'} eq 'all' ) {
- @charset =
- ( 0 .. 9, 'a' .. 'z', 'A' .. 'Z', '#', ',',
- qw(~ ! @ $ % ^ & * ( ) _ + = - { } | : " < > ? / . ' ; ] [ \ `)
- );
- }
- elsif ( $options{'set'} eq 'alpha' ) {
- @charset = ( 'a' .. 'z', 'A' .. 'Z' );
- }
- elsif ( $options{'set'} eq 'upperalpha' ) {
- @charset = ( 'A' .. 'Z' );
- }
- elsif ( $options{'set'} eq 'loweralpha' ) {
- @charset = ( 'a' .. 'z' );
- }
- elsif ( $options{'set'} eq 'numeric' ) {
- @charset = ( 0 .. 9 );
- }
- elsif ( $options{'set'} eq 'alphanumeric' ) {
- @charset = ( 0 .. 9, 'a' .. 'z', 'A' .. 'Z' );
- }
- elsif ( $options{'set'} eq 'misc' ) {
- @charset =
- ( '#', ',',
- qw(~ ! @ $ % ^ & * ( ) _ + = - { } | : " < > ? / . ' ; ] [ \ `)
- );
- }
-
- $options{'set'} = \@charset;
- }
-
- return rand_set(%options);
-}
-
-################################################################################
-# rand_set()
-################################################################################
-sub rand_set {
-
- # Get the options hash
- my %options = @_;
-
- # Make sure the set array was defined
- cluck('set array is not defined') && return if !$options{'set'};
-
- $options{'size'} = 1
- unless exists( $options{'min'} ) || exists( $options{'max'} )
- || exists( $options{'size'} );
-
- # Initialize max and min vars
- $options{'min'} ||= 0;
- $options{'max'} ||= @{ $options{'set'} };
-
- # Make sure the max and min vars are OK
- cluck('min value cannot be larger than max value') && return
- if $options{'min'} > $options{'max'};
- cluck('min value must be a positive integer') && return
- if $options{'min'} < 0 || $options{'min'} != int( $options{'min'} );
- cluck('max value must be a positive integer') && return
- if $options{'max'} < 0 || $options{'max'} != int( $options{'max'} );
-
- # Initialize the size var
- $options{'size'} ||=
- int( rand( $options{'max'} - $options{'min'} + 1 ) ) + $options{'min'};
-
- # Make sure the size var is OK
- cluck('size value must be a positive integer') && return
- if $options{'size'} < 0 || $options{'size'} != int( $options{'size'} );
- cluck('size value exceeds set size') && return
- if $options{'size'} > @{ $options{'set'} };
-
- # Initialize the shuffle flag
- $options{'shuffle'} =
- exists( $options{'shuffle'} ) ? $options{'shuffle'} : 1;
-
- # Get the random items
- my %results = ();
- for ( my $i = 0 ; $i < $options{'size'} ; $i++ ) {
- my $result;
-
- do {
- $result = int( rand( @{ $options{'set'} } ) );
- } while ( exists( $results{$result} ) );
-
- $results{$result} = 1;
- }
-
- my @results = sort { $a <=> $b } keys %results;
-
- # Shuffle the items
- shuffle( \@results ) if $options{'shuffle'};
-
-# Return an array or an array reference, depending on the context in which the sub was called
- if ( wantarray() ) {
- return @{ $options{'set'} }[@results];
- }
- else {
- return \@{ $options{'set'} }[@results];
- }
-}
-
-################################################################################
-# rand_enum()
-################################################################################
-sub rand_enum {
-
- # Get the options hash
- my %options = @_;
-
- # Make sure the set array was defined
- cluck('set array is not defined') && return if !$options{'set'};
-
- return $options{'set'}->[ int( rand( @{ $options{'set'} } ) ) ];
-}
-
-################################################################################
-# rand_date()
-################################################################################
-sub rand_date {
-
- # Get the options hash
- my %options = @_;
-
- # use the Date::Calc module
- eval q{ use Date::Calc };
-
- cluck($@) && return if $@;
-
- my ( $min_year, $min_month, $min_day, $max_year, $max_month, $max_day );
-
- # Get today's date
- my ( $year, $month, $day ) = Date::Calc::Today();
-
- if ( $options{'min'} ) {
- if ( $options{'min'} eq 'now' ) {
- ( $min_year, $min_month, $min_day ) = ( $year, $month, $day );
- }
- else {
- ( $min_year, $min_month, $min_day ) =
- split ( /\-/, $options{'min'} );
- }
- }
- else {
- ( $min_year, $min_month, $min_day ) = ( $year, $month, $day );
- }
-
- if ( $options{'max'} ) {
- if ( $options{'max'} eq 'now' ) {
- ( $max_year, $max_month, $max_day ) = ( $year, $month, $day );
- }
- else {
- ( $max_year, $max_month, $max_day ) =
- split ( /\-/, $options{'max'} );
- }
- }
- else {
- ( $max_year, $max_month, $max_day ) =
- Date::Calc::Add_Delta_YMD( $min_year, $min_month, $min_day, 1, 0, 0 );
- }
-
- my $delta_days =
- Date::Calc::Delta_Days( $min_year, $min_month, $min_day, $max_year,
- $max_month, $max_day, );
-
- cluck('max date is later than min date') && return if $delta_days < 0;
-
- $delta_days = int( rand( $delta_days + 1 ) );
-
- ( $year, $month, $day ) =
- Date::Calc::Add_Delta_Days( $min_year, $min_month, $min_day,
- $delta_days );
-
- return sprintf( "%04u-%02u-%02u", $year, $month, $day );
-}
-
-################################################################################
-# rand_time()
-################################################################################
-sub rand_time {
-
- # Get the options hash
- my %options = @_;
-
- my ( $min_hour, $min_min, $min_sec, $max_hour, $max_min, $max_sec );
-
- if ( $options{'min'} ) {
- if ( $options{'min'} eq 'now' ) {
-
- # Get the current time
- my ( $hour, $min, $sec ) = ( localtime() )[ 2, 1, 0 ];
-
- ( $min_hour, $min_min, $min_sec ) = ( $hour, $min, $sec );
- }
- else {
- ( $min_hour, $min_min, $min_sec ) = split ( /\:/, $options{'min'} );
-
- cluck('minimum time is not in valid time format HH:MM:SS') && return
- if ( $min_hour > 23 ) || ( $min_hour < 0 );
- cluck('minimum time is not in valid time format HH:MM:SS') && return
- if ( $min_min > 59 ) || ( $min_min < 0 );
- cluck('minimum time is not in valid time format HH:MM:SS') && return
- if ( $min_sec > 59 ) || ( $min_sec < 0 );
- }
- }
- else {
- ( $min_hour, $min_min, $min_sec ) = ( 0, 0, 0 );
- }
-
- if ( $options{'max'} ) {
- if ( $options{'max'} eq 'now' ) {
-
- # Get the current time
- my ( $hour, $min, $sec ) = ( localtime() )[ 2, 1, 0 ];
-
- ( $max_hour, $max_min, $max_sec ) = ( $hour, $min, $sec );
- }
- else {
- ( $max_hour, $max_min, $max_sec ) = split ( /\:/, $options{'max'} );
-
- cluck('maximum time is not in valid time format HH:MM:SS') && return
- if ( $max_hour > 23 ) || ( $max_hour < 0 );
- cluck('maximum time is not in valid time format HH:MM:SS') && return
- if ( $max_min > 59 ) || ( $max_min < 0 );
- cluck('maximum time is not in valid time format HH:MM:SS') && return
- if ( $max_sec > 59 ) || ( $max_sec < 0 );
- }
- }
- else {
- ( $max_hour, $max_min, $max_sec ) = ( 23, 59, 59 );
- }
-
- my $min_secs = $min_hour * 3600 + $min_min * 60 + $min_sec;
- my $max_secs = ( $max_hour * 3600 ) + ( $max_min * 60 ) + $max_sec;
-
- my $delta_secs = $max_secs - $min_secs;
-
- cluck('min time is later than max time') && return if $delta_secs < 0;
-
- $delta_secs = int( rand( $delta_secs + 1 ) );
-
- my $result_secs = $min_secs + $delta_secs;
-
- my $hour = int( $result_secs / 3600 );
- my $min = int( ( $result_secs - ( $hour * 3600 ) ) / 60 );
- my $sec = $result_secs % 60;
-
- return sprintf( "%02u:%02u:%02u", $hour, $min, $sec );
-}
-
-################################################################################
-# rand_datetime()
-################################################################################
-sub rand_datetime {
-
- # Get the options hash
- my %options = @_;
-
- # use the Date::Calc module
- eval q{ use Date::Calc };
-
- cluck($@) && return if $@;
-
- my (
- $min_year, $min_month, $min_day, $min_hour, $min_min, $min_sec,
- $max_year, $max_month, $max_day, $max_hour, $max_min, $max_sec
- );
-
- # Get today's date
- my ( $year, $month, $day, $hour, $min, $sec ) = Date::Calc::Today_and_Now();
-
- if ( $options{'min'} ) {
- if ( $options{'min'} eq 'now' ) {
- ( $min_year, $min_month, $min_day,
- $min_hour, $min_min, $min_sec )
- = ( $year, $month, $day, $hour, $min, $sec );
- }
- else {
- ( $min_year, $min_month, $min_day,
- $min_hour, $min_min, $min_sec )
- = $options{'min'} =~ /^(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)$/;
- }
- }
- else {
- ( $min_year, $min_month, $min_day, $min_hour, $min_min, $min_sec ) =
- ( $year, $month, $day, 0, 0, 0 );
- }
-
- if ( $options{'max'} ) {
- if ( $options{'max'} eq 'now' ) {
- ( $max_year, $max_month, $max_day,
- $max_hour, $max_min, $max_sec )
- = ( $year, $month, $day, $hour, $min, $sec );
- }
- else {
- ( $max_year, $max_month, $max_day,
- $max_hour, $max_min, $max_sec )
- = $options{'max'} =~ /^(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)$/;
- }
- }
- else {
- ( $max_year, $max_month, $max_day, $max_hour, $max_min, $max_sec ) =
- ( Date::Calc::Add_Delta_YMD( $min_year, $min_month, $min_day, 1, 0,
- 0 ), 23, 59, 59 );
- }
-
- my ( $delta_days, $delta_hours, $delta_mins, $delta_secs ) =
- Date::Calc::Delta_DHMS(
- $min_year, $min_month, $min_day, $min_hour, $min_min, $min_sec,
- $max_year, $max_month, $max_day, $max_hour, $max_min, $max_sec,
- );
-
- cluck('max date is later than min date') && return
- if ( $delta_days < 0 ) || ( $delta_hours < 0 ) || ( $delta_mins < 0 )
- || ( $delta_secs < 0 );
-
- $delta_secs =
- ( $delta_days * 86400 ) + ( $delta_hours * 3600 ) + ( $delta_mins * 60 ) +
- $delta_secs;
-
- $delta_secs = int( rand( $delta_secs + 1 ) );
-
- ( $year, $month, $day, $hour, $min, $sec ) = Date::Calc::Add_Delta_DHMS(
- $min_year, $min_month, $min_day, $min_hour,
- $min_min, $min_sec, 0, 0,
- 0, $delta_secs
- );
-
- return
- sprintf( "%04u-%02u-%02u %02u:%02u:%02u", $year, $month, $day, $hour,
- $min, $sec );
-}
-
-################################################################################
-# rand_image()
-################################################################################
-sub rand_image {
-
- # Get the options hash
- my %options = @_;
-
- $options{'minwidth'} ||= 1;
- $options{'maxwidth'} ||= 100;
- $options{'width'} ||=
- int( rand( $options{'maxwidth'} - $options{'minwidth'} + 1 ) ) +
- $options{'minwidth'};
-
- $options{'minheight'} ||= 1;
- $options{'maxheight'} ||= 100;
- $options{'height'} ||=
- int( rand( $options{'maxheight'} - $options{'minheight'} + 1 ) ) +
- $options{'minheight'};
-
- $options{'minpixels'} ||= 0;
- $options{'maxpixels'} ||= $options{'width'} * $options{'height'};
- $options{'pixels'} ||=
- int( rand( $options{'maxpixels'} - $options{'minpixels'} + 1 ) ) +
- $options{'minpixels'};
-
- $options{'bgcolor'} ||= _color();
- $options{'fgcolor'} ||= _color();
-
- eval q{ use GD; };
-
- cluck($@) && return if $@;
-
- my $image = new GD::Image( $options{'width'}, $options{'height'} );
-
- my $bgcolor = $image->colorAllocate( @{ $options{'bgcolor'} } );
- my $fgcolor = $image->colorAllocate( @{ $options{'fgcolor'} } );
-
- $image->rectangle( 0, 0, $options{'width'}, $options{'height'}, $bgcolor );
-
- for ( my $i = 0 ; $i < $options{'pixels'} ; $i++ ) {
- my $x = int( rand( $options{'width'} + 1 ) );
- my $y = int( rand( $options{'height'} + 1 ) );
-
- $image->setPixel( $x, $y, $fgcolor );
- }
-
- return $image->png();
-
- sub _color {
- return [ int( rand(266) ), int( rand(266) ), int( rand(266) ) ];
- }
-}
-
-################################################################################
-# shuffle()
-################################################################################
-sub shuffle {
- my $array = shift;
-
- for ( my $i = @$array - 1 ; $i >= 0 ; $i-- ) {
- my $j = int( rand( $i + 1 ) );
-
- @$array[ $i, $j ] = @$array[ $j, $i ] if $i != $j;
- }
-}
-
-1;
-
-=head1 NAME
-
-Data::Random - Perl module to generate random data
-
-
-=head1 SYNOPSIS
-
- use Data::Random qw(:all);
-
- my @random_words = rand_words( size => 10 );
-
- my @random_chars = rand_chars( set => 'all', min => 5, max => 8 );
-
- my @random_set = rand_set( set => \@set, size => 5 );
-
- my $random_enum = rand_enum( set => \@set );
-
- my $random_date = rand_date();
-
- my $random_time = rand_time();
-
- my $random_datetime = rand_datetime();
-
- open(FILE, ">rand_image.png") or die $!;
- binmode(FILE);
- print FILE rand_image( bgcolor => [0, 0, 0] );
- close(FILE);
-
-
-=head1 DESCRIPTION
-
-A module used to generate random data. Useful mostly for test programs.
-
-
-=head1 METHODS
-
-=head2 rand_words()
-
-This returns a list of random words given a wordlist. See below for possible parameters.
-
-=over 4
-
-=item *
-
-wordlist - the path to the wordlist file. A lot of systems have one at /usr/dict/words. You can also optionally supply a Data::Random::WordList object to keep a persistent wordlist. The default is the wordlist distributed with this module.
-
-=item *
-
-min - the minimum number of words to return. The default is 1.
-
-=item *
-
-max - the maximum number of words to return. The default is 1.
-
-=item *
-
-size - the number of words to return. The default is 1. If you supply a value for 'size', then 'min' and 'max' aren't paid attention to.
-
-=item *
-
-shuffle - whether or not the words should be randomly shuffled. Set this to 0 if you don't want the words shuffled. The default is 1. Random::Data::WordList returns words in the order that they're viewed in the word list file, so shuffling will make sure that the results are a little more random.
-
-=back 4
-
-
-=head2 rand_chars()
-
-This returns a list of random characters given a set of characters. See below for possible parameters.
-
-=over 4
-
-=item *
-
-set - the set of characters to be used. This value can be either a reference to an array of strings, or one of the following:
-
- alpha - alphabetic characters: a-z, A-Z
- upperalpha - upper case alphabetic characters: A-Z
- loweralpha - lower case alphabetic characters: a-z
- numeric - numeric characters: 0-9
- alphanumeric - alphanumeric characters: a-z, A-Z, 0-9
- char - non-alphanumeric characters: # ~ ! @ $ % ^ & * ( ) _ + = - { } | : " < > ? / . ' ; ] [ \ `
- all - all of the above
-
-=item *
-
-min - the minimum number of characters to return. The default is 0.
-
-=item *
-
-max - the maximum number of characters to return. The default is the size of the set.
-
-=item *
-
-size - the number of characters to return. The default is 1. If you supply a value for 'size', then 'min' and 'max' aren't paid attention to.
-
-=item *
-
-shuffle - whether or not the characters should be randomly shuffled. Set this to 0 if you want the characters to stay in the order received. The default is 1.
-
-=back 4
-
-
-=head2 rand_set()
-
-This returns a random set of elements given an initial set. See below for possible parameters.
-
-=over 4
-
-=item *
-
-set - the set of strings to be used. This should be a reference to an array of strings.
-
-=item *
-
-min - the minimum number of strings to return. The default is 0.
-
-=item *
-
-max - the maximum number of strings to return. The default is the size of the set.
-
-=item *
-
-size - the number of strings to return. The default is 1. If you supply a value for 'size', then 'min' and 'max' aren't paid attention to.
-
-=item *
-
-shuffle - whether or not the strings should be randomly shuffled. Set this to 0 if you want the strings to stay in the order received. The default is 1.
-
-=back 4
-
-
-=head2 rand_enum()
-
-This returns a random element given an initial set. See below for possible parameters.
-
-=over 4
-
-=item *
-
-set - the set of strings to be used. This should be a reference to an array of strings.
-
-=back 4
-
-
-=head2 rand_date()
-
-This returns a random date in the form "YYYY-MM-DD". 2-digit years are not currently supported. Efforts are made to make sure you're returned a truly valid date--ie, you'll never be returned the date February 31st. See the options below to find out how to control the date range. Here are a few examples:
-
- # returns a date somewhere in between the current date, and one year from the current date
- $date = rand_date();
-
- # returns a date somewhere in between September 21, 1978 and September 21, 1979
- $date = rand_date( min => '1978-9-21' );
-
- # returns a date somewhere in between September 21, 1978 and the current date
- $date = rand_date( min => '1978-9-21', max => 'now' );
-
- # returns a date somewhere in between the current date and September 21, 2008
- $date = rand_date( min => 'now', max => '2008-9-21' );
-
-See below for possible parameters.
-
-=over 4
-
-=item *
-
-min - the minimum date to be returned. It should be in the form "YYYY-MM-DD" or you can alternatively use the string "now" to represent the current date. The default is the current date;
-
-=item *
-
-max - the maximum date to be returned. It should be in the form "YYYY-MM-DD" or you can alternatively use the string "now" to represent the current date. The default is one year from the minimum date;
-
-=back 4
-
-
-=head2 rand_time()
-
-This returns a random time in the form "HH:MM:SS". 24 hour times are supported. See the options below to find out how to control the time range. Here are a few examples:
-
- # returns a random 24-hr time (between 00:00:00 and 23:59:59)
- $time = rand_time();
-
- # returns a time somewhere in between 04:00:00 and the end of the day
- $time = rand_time( min => '4:0:0' );
-
- # returns a time somewhere in between 8:00:00 and the current time (if it's after 8:00)
- $time = rand_time( min => '12:00:00', max => 'now' );
-
- # returns a date somewhere in between the current time and the end of the day
- $time = rand_time( min => 'now' );
-
-See below for possible parameters.
-
-=over 4
-
-=item *
-
-min - the minimum time to be returned. It should be in the form "HH:MM:SS" or you can alternatively use the string "now" to represent the current time. The default is 00:00:00;
-
-=item *
-
-max - the maximum time to be returned. It should be in the form "HH:MM:SS" or you can alternatively use the string "now" to represent the current time. The default is 23:59:59;
-
-=back 4
-
-
-=head2 rand_datetime()
-
-This returns a random date and time in the form "YYYY-MM-DD HH:MM:SS". See the options below to find out how to control the date/time range. Here are a few examples:
-
- # returns a date somewhere in between the current date/time, and one year from the current date/time
- $datetime = rand_datetime();
-
- # returns a date somewhere in between 4:00 September 21, 1978 and 4:00 September 21, 1979
- $datetime = rand_datetime( min => '1978-9-21 4:0:0' );
-
- # returns a date somewhere in between 4:00 September 21, 1978 and the current date
- $datetime = rand_datetime( min => '1978-9-21 4:0:0', max => 'now' );
-
- # returns a date somewhere in between the current date/time and the end of the day September 21, 2008
- $datetime = rand_datetime( min => 'now', max => '2008-9-21 23:59:59' );
-
-See below for possible parameters.
-
-=over 4
-
-=item *
-
-min - the minimum date/time to be returned. It should be in the form "YYYY-MM-DD HH:MM:SS" or you can alternatively use the string "now" to represent the current date/time. The default is the current date/time;
-
-=item *
-
-max - the maximum date/time to be returned. It should be in the form "YYYY-MM-DD HH:MM:SS" or you can alternatively use the string "now" to represent the current date/time. The default is one year from the minimum date/time;
-
-=back 4
-
-
-=head2 rand_image()
-
-This returns a random image. Currently only PNG images are supported. See below for possible parameters.
-
-=over 4
-
-=item *
-
-minwidth - the minimum width of the image. The default is 1.
-
-=item *
-
-maxwidth - the maximum width of the image. The default is 100.
-
-=item *
-
-width - the width of the image. If you supply a value for 'width', then 'minwidth' and 'maxwidth' aren't paid attention to.
-
-=item *
-
-minheight - the minimum height of the image. The default is 1.
-
-=item *
-
-maxheight - the maximum height of the image. The default is 100.
-
-=item *
-
-height - the height of the image. If you supply a value for 'width', then 'minwidth' and 'maxwidth' aren't paid attention to.
-
-=item *
-
-minpixels - the minimum number of random pixels to display on the image. The default is 0.
-
-=item *
-
-maxpixels - the maximum number of random pixels to display on the image. The default is width * height.
-
-=item *
-
-pixels - the number of random pixels to display on the image. If you supply a value for 'pixels', then 'minpixels' and 'maxpixels' aren't paid attention to.
-
-=item *
-
-bgcolor - the background color of the image. The value must be a reference to an RGB array where each element is an integer between 0 and 255 (eg. [ 55, 120, 255 ]).
-
-=item *
-
-fgcolor - the foreground color of the image. The value must be a reference to an RGB array where each element is an integer between 0 and 255 (eg. [ 55, 120, 255 ]).
-
-=back 4
-
-
-=head1 VERSION
-
-0.05
-
-=head1 AUTHOR
-
-Adekunle Olonoh, koolade@users.sourceforge.net
-
-=head1 CREDITS
-
-Hiroki Chalfant
-David Sarno
-
-=head1 COPYRIGHT
-
-Copyright (c) 2000 Adekunle Olonoh. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
-
-=head1 SEE ALSO
-
-Data::Random::WordList
-
-=cut
-