Builtin Library
README.md
attribute.choose
Choose one of several options for every element, by a seeded, weighted draw, and write the chosen option's index to an attribute. The draw is a portable hash of the seed and the element's own number, so one seed deals the same choices on every run, machine and platform, and changing it reshuffles them all. What picks a variant per scattered point for instances.to_points to match on, or a style per building.
Inputs
geometry(Geometry). The elements that each make a choice. A copy carrying the attribute comes out.class(one of point, vertex, primitive). Default"point". Which elements choose.name(String). Default"variant". The attribute the chosen index is written to: an Int, counted from 0 in the order ofweights.weights(List<Float>). How often each option is chosen, relative to the others:{ 5, 3, 1 }chooses the first option five times as often as the third. An option whose weight is zero or negative is never chosen; a list that leaves nothing positive chooses evenly.seed(Float). Default1. Picks which option each element chooses.
Outputs
geometry: the geometry with the chosen index, an Int from 0 to the number of weights less one, written undernameonclass.
Example
local points = g.points.grid({ countX = 30, countZ = 30 })
local chosen = g.attribute.choose({ geometry = points, name = "variant", weights = { 5, 3, 1 }, seed = 7 })
Of the 900 points about five ninths hold 0, a third hold 1 and a ninth hold 2. weights = { 0, 0, 1 } gives every element 2.