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(); }
In reply to Algorithm help needed. by yoda54
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |