Returns a random floating point number or vector within a range of your choice.
float rand(float maxnumber)
float rand(float minnumber, float maxnumber)
vector rand(vector maxvector)
minvector, vector maxvector)
rand( ) can be used effectively for "jitter" by using a small range.
Another good use for
rand( ) might be when selecting a number periodically, such as in a conditional
statement. In the example below, the variable $xDir is given a new value
every 60 frames of the animation:
Returns a random number from -1 to 1 according to a Perlin noise field generator.
float noise(float number)
float noise(float xnum, float ynum)
float noise(vector vector)
If you execute this function with the same argument value repeatedly, the function returns the same random value each time it executes.
If you execute this
function with an argument value that steadily increases or decreases in
fine increments over time, the function returns random values that increase
and decrease over time.
translateY = (noise(time)
* 5 ) + 5;
a random vector value that exists within a spherical or ellipsoidal region
of your choice. An ellipsoid is a sphere scaled along its X-, Y- or Z-axes.
vector sphrand(float radius)
vector sphrand(vector vector)
radius is the radius of a sphere in which the returned vector exists.
vector is the radius of an ellipsoid along the X-, Y-, and Z-axis.
the random values returned by this function, see seed.
$randomVect = sphrand(1);
translateX = rand(-1,1);
a random floating point number or vector. The number returned falls within
a Gaussian (bell curve) distribution with mean value 0.
float gauss(float stdDev)
vector gauss(float XstdDev, float YstdDev)
vector gauss(vector stdDevVector)
stdDev specifies the value at which one standard deviation occurs along the distribution. This gives a one-dimensional Gaussian distribution.
XstdDev and YstdDev specify the values for one standard deviation. This gives a two-dimensional Gaussian distribution in the XY plane. The right component of the vector returned is 0.
stdDevVector specifies the vector component values for one standard deviation. This gives a three-dimensional distribution.
To control the random values returned by this function, see seed.
note the results fall outside the given value of 5 (-5 to 5) because the value determines the "standard deviation" range defining the bell curve:
|seed( )||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
int seed(int number)
(frame == 1) seed(1);
These are just a few functions available to use in expressions or MEL scripts. Find more math functions by using the Maya online docs menu: Help > Mel Command Reference.