|We don't bite newbies here... much|
Difficulty in randomizationby Anonymous Monk
|on Mar 04, 2012 at 21:08 UTC||Need Help??|
Anonymous Monk has asked for the
wisdom of the Perl Monks concerning the following question:
I have the following task:
I have an empty array of length say 600 and a number, say 10.
I want to create 1000 such arrays (and subsequently strings using 'join') by randomly assigning 10 positions in each array to be 'X' while the remaining 590 will be '-'.
I did the following:
My problem is that I must be doing something wrong, because not all 600 strings produced have 10 positions with 'X' each. And I am suspecting that in my first for loop, I must somehow "remove" the position that is assigned a 'X' in each randomization, because if, for example, in the first run, I assign the 'X' in position 55, the next rand(600) might also give 55 and I will miss one assignment.
How can this be solved?