Python Forum

Full Version: Assign random value
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a file that contains only x's and 2's. I want to change the x's to either 1 or 2 and the sum of 1's in the new file must be exactly 10000. The total number of x in the current file is 87505.

Any tips on how this is done?
Here's a portion of the said file:
       2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 x x x x x x x x x x x 2 2
       2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2                      
       2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 x x x x x x x x x x x 2 2
       2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2                       
       2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 x x x x x x x x x x x 2 2
       2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2                        
       2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 x x x x x x x x x x x 2 2
       2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 
Would you know number of x's in advance?
Yes. I just counted them on notepad. I want the file to have the same format which I created manually.