in reply to Difficulty in randomization

Considering that 10 is much smaller than 600, I'd do:
my @array = ('-') x 600; foreach (1 .. 10) { my $i = int rand 600; redo if $array[$i] eq 'X'; $array[$i] = 'X'; } my $joined_string = join "", @array;
In theory, this may run "for ever", but in practice it will run fast enough.

Replies are listed 'Best First'.
Re^2: Difficulty in randomization
by jwkrahn (Abbot) on Mar 05, 2012 at 00:28 UTC

    Same thing without the array:

    my $joined_string = '-' x 600; foreach ( 1 .. 10 ) { my $i = int rand 600; redo if 'X' eq substr $joined_string, $i, 1; substr $joined_string, $i, 1, 'X'; }