Builtin Library
README.md
field.rand
A deterministic unit draw in [0, 1) for each element, keyed by a seed, a scope and the element's number.
The form rand.unit(seed, ...scope, id) builds. The draw equals hash.unitFloat(seed, graphId, compositePath, nodeId, channel, id) of @builtin::systems.procgen.proc.hash to the bit, with compositePath empty for a three-entry scope: the scope's prefix is folded once and the element folded on the device by the rand prelude. Unwired, id is the number of the element the field is read at. field.random is this draw scaled to a range.
Inputs
seed(Float). Default1. Picks which draw this is. The same seed replays the same value at every element on every machine.scope(List<Value>). The scope the draw is keyed by:{ graphId, nodeId, channel }, or{ graphId, compositePath, nodeId, channel }. Two draws sharing a seed and a scope are identical.id(Any, optional). The element number, as a Field or Column. Left unwired, the number of the element the draw is read at.
Outputs
field: a Float field in [0, 1).
Example
local points = g.points.grid({ countX = 4, countZ = 1, spacing = 1 })
local out = g.attribute.set({ geometry = points, name = "v", value = g.field.rand({ seed = 4, scope = { "trees", "spread", 0 } }) })
v holds 0.8453, 0.9510, 0.3632, 0.1979, the values hash.unitFloat(4, "trees", "", "spread", 0, id) answers for ids 0 to 3.