pcrew has asked for the wisdom of the Perl Monks concerning the following question:
my conditional code for 2f:ff:ff is:sub mac { $cnt = 3; $mac[0] = "00"; $mac[1] = "96"; $mac[2] = "14"; while ($cnt < 6) { $rand = rand(255); if ($rand < 5) { $rand += 2; $hex = sprintf("%X", $rand); } else { $hex = sprintf("%X", $rand); } $mac[$cnt] = $hex; $cnt++; }
The problem is that the above conditional loop gets stuck when executing. any help is higly appreciated.sub mac { $cnt = 3; $mac[0] = "00"; $mac[1] = "96"; $mac[2] = "14"; while ($cnt < 6) { if ($cnt ==4) { $rand = rand(47); } else { $rand = rand(255); if ($rand < 5) { $rand += 2; $hex = sprintf("%X", $rand); } else { $hex = sprintf("%X", $rand); } $mac[$cnt] = $hex; $cnt++; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how to use conditional loops when using while loop
by ikegami (Patriarch) on Jul 28, 2005 at 15:56 UTC | |
|
Re: how to use conditional loops when using while loop
by Random_Walk (Prior) on Jul 28, 2005 at 16:16 UTC | |
by ikegami (Patriarch) on Jul 28, 2005 at 16:18 UTC | |
by Random_Walk (Prior) on Jul 28, 2005 at 16:39 UTC | |
by ikegami (Patriarch) on Jul 28, 2005 at 16:51 UTC | |
|
Re: how to use conditional loops when using while loop
by Forsaken (Friar) on Jul 28, 2005 at 16:37 UTC | |
|
Re: how to use conditional loops when using while loop
by wink (Scribe) on Jul 29, 2005 at 02:46 UTC |