Here's a more detailed explanation on what I've tried to achieve and what I want to achieve.
This is for my JavaScript game project for opening a shipment of goods.
Depending on the shipment quality, you can get:
- A different random set of items and
- a random amount of each item but
- the combined value of all items has to be between two minimum and maximum values AND
- I want to add some sort of limitation for the amount of each item where I don't want
85 lemons
generated because the value of each lemon is1
I currently have the following:
Let's say that one of my "shipments" is defined as an object.
let shipment = {
name: 'common',
items: ['lemons', 'oranges', 'apples', 'plums'],
minValue: 170,
maxValue: 230
}
Now, out of this object I want to generate the random amount of items
so that their sum of values falls between those two min and max values.
The value of each item is stored in my database but for the sake of this example, let's say that their values are defined in a completely different array:
let values = [5, 6, 2, 10]
The order of the elements in the values array corresponds with the value for each item in the items array.
I also want when the algorithm generates an amount for an item in the items
array, its pushed into a new result
array:
result.push({name: itemName, amount: itemAmount});
So that after the entire generating of those items is done, each item and its corresponding amount generated is an element(object) in the result array that I can use.
I'm using Node.js.