Add random amount of random items from one list to another?

I have a list that contains every item in my game and a list list for chest contents. I want to randomly choose some items from the main items list to put in the chest list, but based on a rarity enum in the item class. Some ideas maybe?

Sorry I don’t have any code, I’m at school right now, my stuff is at home. I don’t think it is that necessary in this case anyways.

The “hard” part of your question is handling the rarity. I can think of two approaches. Both solutions involve defining a value for rarity rather than an enum. In the first one you need an integer value, and I’d do it in terms of abundance. So say your rarest item is given a value of 2. All other items are relative to the rarest. So if next rarest is twice abundant, it would get a value of 4. And if you had one that was 3 1/2 as abundant, it would get a value of 7.

Once defined, you construct the ‘store’ array. You populate it based on the abundance value. So you for the item with a value of 7, it will have 7 entries in the list. You populate the chest by simply selecting one from the length of the list.

The second approach is similar to the first in that you assign abundance values, but they don’t have to be integers. So say the rarest has a value of 1.0, the next rarest might have a value of 1.5 for example. To get a random entry, you first sum all the abundance values. Then you generate a random value based on all the abuncance:

val = Random.Range(0.0,totalAbuncance);

Then you walk your array adding up the abundance values as you go. When the sum is greater than your ‘val’, that is the entry that goes in the chest.

well i can push you in the right direction.

first I would make the rarity of the items so

var rarity = #;

and make it into a static var.
Then in your chest script make it call your array of items.
the chest should have a built in array of GameObjects
var ItemsInChest = GameObject;

var size = 0;
// make that how many items you want in the chest

var min = 10;
var max = 15;

function start()
size = Random.Range(min, max)

// so it chooses random amount of items

now this is just a basic over vew, if you have the array already you can just make it static and then do

var ItemsToGet = 0;

function start()
// make how ever many randum itomes you want to be in chest
// get those items from your items array
//add those items to this chest array
//set amount for those items

now with out knowing the type of array you are using i have no more i really can say.
hope it helped if not i will delete it to save space.