yoda54 has asked for the wisdom of the Perl Monks concerning the following question:
I can't seem to put this in code, perhaps its too much intoxication lately... :) I have a bunch of objects with a $objref->randomturn() method. What I need is each object to act in lowest to highest order. In the event that X number of objects draw the same number, those X objects need to re-draw until they have drawn a unique number. I am storing all my object references in an array, so I'm thinking about something like this.
As usual thanks for any help!
package SOMECLASS; sub new { blah blah blah } sub randomturn { my $self = shift @_; my $random = int(rand(2000)); return $random; } 1; package main; use SOMECLASS; my $array; #gen objects for(1..100) { push @$array, SOMECLASS->new(); } foreach (@$array) { #build some data structure to store 1) drawn number 2) object refe +rence 3) turn order ? #generate turn order, use recursive function to redraw until there + is no tie $_->randomturn(); } #Finally... #sort data structure & foreach(@$turnorder) { # @$turnorder or whatever data structure... $_->dosomething(); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Algorithm help needed.
by GrandFather (Saint) on Jul 23, 2006 at 22:45 UTC | |
by sgifford (Prior) on Jul 24, 2006 at 00:44 UTC | |
by BrowserUk (Patriarch) on Jul 24, 2006 at 02:28 UTC |