How to reproduce exact values of random numbers



Some applications and simulation objects might benefit from using random generator of numbers. One example can be random distribution of particles of various size that is available in the object library. On the other hand, it might not be desirable that the random distribution changes with each run of the simulation or the related script.

For example, the following command will generate random number between 1 and 10:


Nevertheless, using the rand(); command on it’s own will always generate a random number that will be hard to reproduce.

The solution is to use randreset(seed); together with the rand(); command. It resets the seed value of the random function and the rand(); command will always produce identical sequence of random numbers for given seed value as shown in the following example:

for (i=1:3) {

This code will print three identical sequences of three random numbers. If the randreset(); line is removed, it will simply plot nine random numbers. Additionally, different seed value will produce different sequence of random number.

정확히 동일한 랜덤 숫자들을 재현하는 방법