I'm trying to implement my Processing code so that the line of the code will NOT run 5% of the total number of the times that a line of the code is supposed to run. But the crucial additional point is that the instance that the line would not be running should be unpredictable (random).
For instance, let's say that the code is to run 20 times. I want the code to not run in one of the 20 instances. This one instance would be 5% of the total (20) [1/20=5%]. This has to be random so that for example, in the first iteration of 20, the code does not run in the 3rd trial, and in the second iteration, the line does not run in the 10th trial.
This is the illustration:
First iteration: [1, 2, 3 (Don't run), 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
Second iteration: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10 (Don't run), 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
Third iteration: ...
I wrote the pseudocode below but wonder whether there is a better way of doing this.
create an array [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
take a number out of a set randomly and if the number is NOT 1:
println("run")
get rid of the selected number within an array
if the set is empty, get a new set
Aucun commentaire:
Enregistrer un commentaire