What it does
Uses rand(@ptnum) to produce a random value that is unique per point but constant over time, because the seed (the point number) does not change frame to frame. Assigning it to a vector like @Cd seeds R, G and B independently.
When to use it
Use it for any per-point variation that should stay put: random colour, random scale, random offsets, random group membership. It is the seed you reach for before adding time or class-based variation.
The VEX code
// rand() of the point number is stable per point and per frame.
@Cd = rand(@ptnum); // vector: random RGB
f@size = fit01(rand(@ptnum), 0.5, 1.5); // float: random scale
Inputs and assumptions
- Runs per point in an Attribute Wrangle over points.
@ptnumis the seed; it is stable, so the result does not flicker.- Assigning
rand()to a vector randomises each channel; to a float, a single value.
Common mistakes
- Seeding off a value that changes each frame (like
@Time) when you wanted a stable look - use@ptnum. - Expecting different results for two points that share a point number after a merge or copy - offset the seed (e.g.
rand(@ptnum + @primnum * 7919)). - Wanting per-piece (not per-point) variation - seed off a
@classor@nameinstead of@ptnum. - Assuming
rand()is uniform enough for cryptographic use - it is a fast hash for look variation only.
Frequently asked questions
Why use rand(@ptnum) instead of rand(@Time)?
@ptnum is stable per point, so the randomness stays put frame to frame. Seeding off @Time makes values change every frame, which flickers.
How do I randomise per piece instead of per point?
Seed off a per-piece attribute such as i@class or s@name (for example rand(i@class)) so every point in a piece gets the same value.