我有一组随机数和零。我如何从它们中随机选择一个正数,并且有一定概率,比如20%用另一个值替换它,否则保持不变?
答案 0 :(得分:1)
伪代码
While Selected Number Is Not A Positive Number
Select Random Index Between 0 and Size of Array - 1
If Number at Index is Not Positive then continue to next iteration
Else
Generate Random Number Between 0 and 1
If Random Number is less than 0.2 //20%
Set Array[selected index] = some other value