Hm. You construct your arrays all fine, but after they are constructed, the random() function isn't called when you reference an array item, but you absolutely need runtime randomness for your layout to work.

You have to add a bit of magic to your arrays with tie.

use Tie::Array; @ISA = qw(Tie::StdArray); sub FETCH { my ($self,$index) = @_; if (ref($self->[$index]) =~ /CODE/) { return $self->[$index]->(); } $self->[$index]; }

Now convert all your array elements which are dynamically constructed (i.e via concatenation of some strings and calls to e.g. random()) into anonymous subs, and tie those arrays:

my @MagicItems; tie @MagicItems, main; # main, or the package of your +code @MagicItems = ( "can use all magic items", "can not use any magic items", sub { "can only use magic items in the ".random("MITp")." group"}, sub { "can not use magic items in the ".random("MITp")." group"}, sub { "causes $MagicItemGroup[rand @MagicItemGroup] to dysfunction + $radius"}, sub { "causes $MagicItemGroup[rand @MagicItemGroup] to loose their + power $radius"}, sub { "attracts $MagicItemGroup[rand @MagicItemGroup] $radius"}, sub { "repels $MagicItemGroup[rand @MagicItemGroup] $radius"}, sub { "destroys $MagicItemGroup[rand @MagicItemGroup] $radius"}, );

Do this with every array which has randomly constructed items. Then

for (1..10) { print $MagicItems[rand(@MagicItems,)],"\n"; };

will yield e.g.

can not use any magic items can not use magic items in the Magical Liquids group can not use magic items in the Musical Instruments group destroys magic items in the Scrolls group in a 20' radius repels magic items in the Bags & Bottles group in a 20' radius causes all magic items to loose their power in a 20' radius can not use magic items in the Rods group causes magic items in the Humorous Items group to loose their power in + a 20' radius can only use magic items in the Weird Stuff group can only use magic items in the Humorous Items group

Solving the static radius problem is left as an exercise to the reader.

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

In reply to Re^2: Creating a random generator by shmem
in thread Creating a random generator by Lady_Aleena

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.