Angelo is a procedural generation library written in pure Swift.
You can find more details about it here:
Angelo currently has the following tools to assist you with procedural generation:
Weighted lists are lists in which each element has an associated weight with it. This allows the selection of random elements from the list, but increasing/decreasing the chance of a specific element to be selected.
In the example below, we create a list and add an element to it:
let list = WeightedList<Int>()
list.add(20) // Since we are not specifying a weight, the default is 1
Note that the list has a type associated with it, defined by the <Int> notation.
Now, let's add another element.
list.add(40) // Since we are not specifying a weight, the default is 1
If try to select an element by using list.randomElement(), we'll get either 20 or 40, each with 50% of chance.
let element = list.randomElement() // element has //
// 50% of chance of being 20 and
// 50% of chance of being 40,
// since both have the same weight (1)
Now, suppose we add another element with weight 2 and try to select another random element:
try? list.add(80, weight: 2)
let element = list.randomElement() // element has:
// 50% of chance of being 80
// 25% of chance of being 20 and
// 25% of chance of being 40.