Modifying array with probability

Hi,

I'm implementing an algorithm and it asks to modify a 15x15 2d array with a certain probability (0.1). How exactly do I implement this?

The modification to be made is pretty simple (flipping a random position on the array). But how do I ensure it changes with this probability?

I should mention that this mutation is supposed to be repeated after a certain time.

Thanks,
openSource
By probability 0.1 you mean 10%?

Generate a random number in the range [ 1..10 ] (inclusive) and if the random number is equal to 1, then mutate. (NB: easier would be to generate a random number in the range [0..9] and check for 0, but my above example tried to make it more obvious how it worked).


Topic archived. No new replies allowed.