in reply to Generating 0 .. N Randomly and Efficiently
This looks like shuffling a deck of cards. Wouldn't it be easier to create an array of the appropriate size, populate it, shuffle it, and then print the numbers?
Hope this helped,#!/usr/bin/perl use strict; use warnings; my $SIZE = 10; my @a = (0..$SIZE); for (@a) { my $i = int(rand($SIZE+1)); ($a[$i],$a[$_])=($a[$_],$a[$i]) } print "$_\n" for @a;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Generating 0 .. N Randomly and Efficiently
by Limbic~Region (Chancellor) on Oct 19, 2004 at 16:23 UTC | |
by ikegami (Patriarch) on Oct 19, 2004 at 16:33 UTC | |
by Limbic~Region (Chancellor) on Oct 19, 2004 at 16:37 UTC |