How can I best generate a static array of random number on demand?

后端 未结 8 789
北海茫月
北海茫月 2021-01-14 06:56

An application I\'m working on requires a matrix of random numbers. The matrix can grow in any direction at any time, and isn\'t always full. (I\'ll probably end up re-imple

8条回答
  •  一整个雨季
    2021-01-14 07:07

    As far as I see, there are 2 basic algorithms possible here:

    • Generate a new random number based on func(seed, coord) for each coord
    • Generate a single random number from seed, and then transform it for the coord (something like rotate(x) + translate(y) or whatever)

    In the first case, you have the problem of always generating new random numbers, although this may not be as expensive as you fear.

    In the second case, the problem is that you may lose randomness during your transformation operations. However, in either case the result is reproducible.

提交回复
热议问题