in reply to Finding a random position within a long string (Activeperl Build 822)
Depending on what you mean by "somehow equally distributed over the string", this may do the trick
my $percent = 10; my $string = 'A' x 20; for ( 1 .. $percent / 100 * length $string ) { my $pos = int rand length $string; substr( $string, $pos, 1 ) = '?'; }
Update: int isn't needed
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Finding a random position within a long string (Activeperl Build 822)
by mwah (Hermit) on Oct 12, 2007 at 21:47 UTC | |
|
Re^2: Finding a random position within a long string (Activeperl Build 822)
by kyle (Abbot) on Oct 12, 2007 at 21:39 UTC | |
by FunkyMonk (Bishop) on Oct 12, 2007 at 21:42 UTC |