Get a randomized aberrancy around given value

后端 未结 4 2145
栀梦
栀梦 2021-01-27 02:30

I would like to add a kind of ripple to an array of known values of type double. I point that out because Random.Next / Random.NextDouble() behave different.

4条回答
  •  独厮守ぢ
    2021-01-27 02:56

    Choose a random number (symmetric about zero) for each step between successive numbers. Then, add it to the first, and subtract it from the second:

    for(int i=1; i

    This should ensure that the sum of the array stays the same (modulo floating point error), while the array elements are all modified.

提交回复
热议问题