Generating Specials
Take a look at how to generate the list of specials, regular items and items on the specials.
Generating the list of specials
We’ll start with the list of specials since it’s conceptually simpler and a prerequisite of other generators. The method here is to first extract the list of all item names from the price list, and then create a matching table of specials. Let’s take a look at how it can be done.
special_list(PriceList) ->
Items = [Name || {Name, _} <- PriceList],
?LET(Specials, list({elements(Items), choose(2,5), integer()}),
lists:ukeysort(1, Specials)). % no dupes
The generated list of specials contains the name of the item, how many of them are required for the special to apply, and then the price for the whole group. The specials are generated from randomly selected entries from the item list with the duplicates removed so that there is always a matching non-special item to any special one. Note that the special price can be higher than the non-special price with this generator.
Generating the list of regular items
It is a bit tricky to generate the list of items that are never special. We’ll call them regular items. We have to make it so we generate zero or more regular items, as long as the maximal value is below any specials for it. Let’s take a look at how it can be done.
Get hands-on with 1400+ tech skills courses.