Jones, Scott (GE Money, consultant) wrote:
Yes, just a scramble of a small but gradually increasing list of words..
I'd like to have them scrambled.. And then output in a string, a list of
scrambled words..

I'm attaching something I wrote recently in Perl. It's fairly straightforward, just put the list of words at the bottom. It's meant to give you a random list using the words after __DATA__. It can have duplicates and doesn't have to use all the words. But if you save that as RandomText.pm in a folder and run this from that folder:

$ perl -e 'use RandomText; print RandomText::random_text(10);'

package RandomText;
use strict;
use base qw(Exporter);
use Debug;
our @EXPORT = qw(random_text);
our $words;
sub words {
    return $words ||= do {
        chomp(my (@w) = <DATA>);
        \...@w;
} }

sub random_text {
    my $length = shift;
    my $text = '';
    my $words = &words;
    for (1 .. $length) {
        $text .= $words->[int rand(@$words)] . " ";
} return $text;
}

1;

__DATA__
Abundant
Adjo
Advance
Afrikaisi
Aisha
Aishe
Akana
Akhom
Ako
Akori
Akori
Akorit
Aloli


/*
PLUG: http://plug.org, #utah on irc.freenode.net
Unsubscribe: http://plug.org/mailman/options/plug
Don't fear the penguin.
*/

Reply via email to