Sets a seed value the gauss, rand, and sphrand functions use to generate random numbers. If you assign a value to the seed then execute the gauss, rand, or sphrand function repeatedly, an identical sequence of random numbers is generated. For clarification, see the example below and Reproduce randomness.
number sets an arbitrary number to be used as the seed value.
Suppose you create a NURBS sphere named Ball then enter this expression:
Ball.translateX = rand(5);
When you rewind the animation, Ball’s translateX attribute receives a random value between 0 and 5, for example, 1.392. When you play the animation, the translateX attribute receives a different random value between 0 and 5 each frame.
When you rewind the animation again, the translateX attribute receives a value that’s different from the value it received the first time you rewound, for example, 3.223.
When you play the animation again, the translateX attribute receives a value each frame that’s different from the values it received the first time you played the animation. In short, every time the rand(5) executes, it gives a different random value.
Suppose you change the expression to this:
if (frame == 1) seed(1); Ball.translateX = rand(5);
Rewinding the scene to frame 1 executes the seed(1) function. It then assigns translateX a random value between 0 and 5, for example, 4.501.
When you play the animation, the rand(5) function executes each frame and returns a different value. Example returned values follow:
Frame | Value |
---|---|
1 | 4.501 |
2 | 3.863 |
3 | 3.202 |
4 | 3.735 |
5 | 2.726 |
6 | 0.101 |
Each time you rewind and play the animation, translateX receives the same sequence of random values.
For different seed values, the sequence of numbers returned will differ. You can’t predict the values in the number sequence based on the value of the seed.
Suppose you change the expression to this:
if (frame == 1) seed(500); Ball.translateX = rand(5);
The rand(5) function returns these values as you rewind and play the animation:
Frame | Value |
---|---|
1 | 4.725 |
2 | 2.628 |
3 | 0.189 |
4 | 0.004 |
5 | 4.834 |
6 | 0.775 |
By changing the seed function’s value, you change the sequence of random numbers generated.
A common mistake while using the seed function follows:
seed(1); Ball.translateX = rand(5);
When you rewind the animation, Ball’s translateX attribute receives the value 4.501. When you play the animation, the translateX attribute receives 4.501 each time the expression executes.
Because you assign a value (1) to the seed before each execution of rand(5), you initialize the random number sequence. The rand(5) function therefore returns the first value of the number sequence each time it executes.