Format

generator(type, A, B, rand)

Args

  • type: The type of generator object, which determines what kind of results it produces
  • A: One extreme of the generator results
  • B: The other extreme
  • rand: Type of random distribution used

Creates a generator that can be used to produce a random value. This generator can be used in client-side particle effects, or it can be used in proc code. The types of values it can produce are numbers, 2D or 3D vectors, or colors (a text string like “#rrggbb” or a color matrix).

Generator typeResult typeDescription
numnumA random number between A and B.
vectorvectorA random vector on a line between A and B.
boxvectorA random vector within a box whose corners are at A and B.
colorcolor (string) or color matrixResult type depends on whether A or B are matrices or not. The result is interpolated between A and B; components are not randomized separately.
circlevectorA random XY-only vector in a ring between radius A and B, centered at 0,0.
spherevectorA random vector in a spherical shell between radius A and B, centered at 0,0,0.
squarevectorA random XY-only vector between squares of sizes A and B. (The length of the square is between A*2 and B*2, centered at 0,0.)
cubevectorA random vector between cubes of sizes A and B. (The length of the cube is between A*2 and B*2, centered at 0,0,0.)

The optional rand argument determines the type of random distribution.

UNIFORM_RANDDefault. Random values are uniformly likely to be chosen.
NORMAL_RANDApproximates a Gaussian normal distribution, but on a finite interval. Values closest to the mean are more likely to be chosen, while the extremes are much less likely.
LINEAR_RANDThe probability of choosing a number is proportional to its absolute value.
SQUARE_RANDThe probability of choosing a number is proportional to its square.

The result of calling generator() is a datum of type /generator and you can get a random value from it by calling its Rand() proc.

var/generator/G = generator("num", -1, 1)    // generates a random number between -1 and 1
world << G.Rand()   // generate a number and output it to world

Note

Worlds compiled in older BYOND versions before vector will return lists from vector generators.

See also