Random.range not random?

im trying to randomize my loot system, i use 2 random numbers to do this, one for drop chance and one for picking the loot out of a list.

the problem is every time i generate loot its the first on the list.
can someone please show me what im doing wrong?

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class Loot : MonoBehaviour {
    public ItemDatabase itemDatabase;
    public List<Item> lootList;
    public List<Item> itemDrop;
    public Rigidbody2D physicalLootPrefab;
    public float lootRNG;
    public int pickerRNG;
    void Start () {
        itemDatabase = gameObject.GetComponent<ItemDatabase>();


    }
    void Update(){
        lootRNG = Random.Range (0.0f, 100.1f);
        pickerRNG = Random.Range (0, 22);
    }
    public void LootTable(Transform enemy, EnemyStats type){
        switch (type.enemyType){

        case EnemyStats.EnemyType.Lowly:{

            lootList = new List<Item>();
            for(int i = 0; i < itemDatabase.items.Count; i++){
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Common){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Uncommon){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Rare){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Rarer){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.SaughtAfter){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Legend){
                    lootList.Add (itemDatabase.items[i]);
                }

            }
            LootPicker(enemy);
        break;
        }
        default:{
            break;
        }
        }
    }
    void LootPicker(Transform enemy){

        if (lootRNG >= 50.0f && lootRNG <= 75.0f) {
            if(lootList[pickerRNG].itemRarity == Item.Rarity.Common){
                itemDrop.Add(lootList[pickerRNG]);
                MakeLoot(enemy);
            }
        }
        if(lootRNG > 75.0f && lootRNG <= 87.5f){
            if(lootList[pickerRNG].itemRarity == Item.Rarity.Uncommon){
                itemDrop.Add(lootList[pickerRNG]);
                MakeLoot(enemy);
            }
        }
        if(lootRNG < 93.7f && lootRNG >= 87.5f){
            if(lootList[pickerRNG].itemRarity == Item.Rarity.Rare){
                itemDrop.Add(lootList[pickerRNG]);
                MakeLoot(enemy);
            }
        }
        if(lootRNG < 97.0f && lootRNG >= 93.7f){
            if(lootList[pickerRNG].itemRarity == Item.Rarity.Rarer){
                itemDrop.Add(lootList[pickerRNG]);
                MakeLoot(enemy);
            }
        }
        if(lootRNG < 99.0f && lootRNG >= 97.0f){
            if(lootList[pickerRNG].itemRarity == Item.Rarity.SaughtAfter){
                itemDrop.Add(lootList[pickerRNG]);
                MakeLoot(enemy);
            }
        }
        if(lootRNG >= 99.0f){
            if(lootList[pickerRNG].itemRarity == Item.Rarity.Legend){
                itemDrop.Add(lootList[pickerRNG]);
                MakeLoot(enemy);
            }
        }
    }
    void MakeLoot(Transform target){
        Vector3 position = new Vector3(target.transform.localPosition.x, target.localPosition.y, 0);
        physicalLootPrefab = Instantiate(physicalLootPrefab, position, Quaternion.identity)as Rigidbody2D;
       
    }
}

You set the lootRNG and pickerRNG in Update, but you use it in the ‘LootPicker’ function, called by the ‘LootTable’ function. When/where is ‘LootTable’ is called? Is it called before the first time ‘Update’ is called?

Why is lootRNG and pickerRNG set in Update anyways???

because it cycles both random numbers.
LootTable() is called when an enemy dies.

Random.Range is about as random as these things get. Those calls in Update should absolutely be removed, though. Only call functions when you actually need them.

–Eric

1 Like

As @Eric5h5 said, you shouldn’t do your random in the Update function but in the LootPicker function.

You should also use “if else”, because your game is gonna check EVERY “if” even if it enters in the first one… that’s a waste of time!

The code below has no sense…

            for(int i = 0; i < itemDatabase.items.Count; i++){
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Common){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Uncommon){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Rare){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Rarer){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.SaughtAfter){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Legend){
                    lootList.Add (itemDatabase.items[i]);
                }
            }

Whatever the item rarity, you will add it to the same list… so why are you checking his rarity ?

if(lootRNG >= 99.0f){
            if(lootList[pickerRNG].itemRarity == Item.Rarity.Legend){
                itemDrop.Add(lootList[pickerRNG]);
                MakeLoot(enemy);
            }
        }

So, I have 1% chance of dropping a Legend item THEN I have (nbLegendItems / 22) % to drop it… are you sure you want to do that ? :eyes:

i never said i was done writing the script, i just had issues with the random.range being a zero every call, i tried putting it in Update(); still did it.
if you look closer there is only ONE type of enemy… guess what kind that is? maybe a world drop.

I’m trying to understand what you’re doing by reading your code, 'cause the error can come from a bad logic.

Random.Range should work even if you put it in the Update function. Where do you print the result of this random ?

i set it to a public var to see it not working. lo and behold it shows up as a random, but in practice. i only get the first item in the database.
i can show you all 3 scripts if you want. the full loot script is kinda lengthy.

i took your advice and moved the rando’s to the method they are used, still not random like i want

“i set it to a public var” - public variables take their initial values from the inspector, not from what is set in code. So if you’re trying to use that value before it’s been properly assigned, that’s why it will come out as the same every time.

To view the value of private variables during runtime, change your inspector to Debug view, don’t change the scope of your variables to public.

Can you tell me what it prints you:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Loot : MonoBehaviour {
    public ItemDatabase itemDatabase;
    public List<Item> lootList;
    public List<Item> itemDrop;
    public Rigidbody2D physicalLootPrefab;
    public float lootRNG;
    public int pickerRNG;
    void Start () {
        itemDatabase = gameObject.GetComponent<ItemDatabase>();
    }
    public void LootTable(Transform enemy, EnemyStats type){
        switch (type.enemyType){
        case EnemyStats.EnemyType.Lowly:{
            lootList = new List<Item>();
            for(int i = 0; i < itemDatabase.items.Count; i++){
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Common){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Uncommon){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Rare){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Rarer){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.SaughtAfter){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Legend){
                    lootList.Add (itemDatabase.items[i]);
                }
            }
Debug.Log("items in list: " + lootList.Count);
            LootPicker(enemy);
        break;
        }
        default:{
            break;
        }
        }
    }
    void LootPicker(Transform enemy){
        lootRNG = Random.Range (0.0f, 100.1f);
        pickerRNG = Random.Range (0, 22);

Debug.Log("lootRNG: " + lootRNG + ", pickerRNG: " + pickerRNG);

        if (lootRNG >= 50.0f && lootRNG <= 75.0f) {
            if(lootList[pickerRNG].itemRarity == Item.Rarity.Common){
                itemDrop.Add(lootList[pickerRNG]);
                MakeLoot(enemy);
            }
        }
        if(lootRNG > 75.0f && lootRNG <= 87.5f){
            if(lootList[pickerRNG].itemRarity == Item.Rarity.Uncommon){
                itemDrop.Add(lootList[pickerRNG]);
                MakeLoot(enemy);
            }
        }
        if(lootRNG < 93.7f && lootRNG >= 87.5f){
            if(lootList[pickerRNG].itemRarity == Item.Rarity.Rare){
                itemDrop.Add(lootList[pickerRNG]);
                MakeLoot(enemy);
            }
        }
        if(lootRNG < 97.0f && lootRNG >= 93.7f){
            if(lootList[pickerRNG].itemRarity == Item.Rarity.Rarer){
                itemDrop.Add(lootList[pickerRNG]);
                MakeLoot(enemy);
            }
        }
        if(lootRNG < 99.0f && lootRNG >= 97.0f){
            if(lootList[pickerRNG].itemRarity == Item.Rarity.SaughtAfter){
                itemDrop.Add(lootList[pickerRNG]);
                MakeLoot(enemy);
            }
        }
        if(lootRNG >= 99.0f){
            if(lootList[pickerRNG].itemRarity == Item.Rarity.Legend){
                itemDrop.Add(lootList[pickerRNG]);
                MakeLoot(enemy);
            }
        }
    }
    void MakeLoot(Transform target){
        Vector3 position = new Vector3(target.transform.localPosition.x, target.localPosition.y, 0);
        physicalLootPrefab = Instantiate(physicalLootPrefab, position, Quaternion.identity)as Rigidbody2D;
      
    }
}

took your advice, still all green potions :[

this is the entire script
the inspector, when the random’s are set to public, change. but the output of items is the first one in itemDatabase

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class Loot : MonoBehaviour {
    public ItemDatabase itemDatabase;
    public List<Item> lootList;
    public List<Item> itemDrop;
    public Rigidbody2D physicalLootPrefab;
    float lootRNG;
    int pickerRNG;
    void Start () {
        itemDatabase = gameObject.GetComponent<ItemDatabase>();


    }
    void Update(){


    }
    public void LootTable(Transform enemy, EnemyStats type){
        switch (type.enemyType){
        case EnemyStats.EnemyType.Lowly:{
            lootList = new List<Item>();
            for(int i = 0; i < itemDatabase.items.Count; i++){
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Common){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Uncommon){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Rare){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Rarer){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.SaughtAfter){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Legend){
                    lootList.Add (itemDatabase.items[i]);
                }
            }
            LootPicker(enemy);
        break;
        }
        case EnemyStats.EnemyType.Basic:{
            for(int i = 0; i < itemDatabase.items.Count; i++){
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Common){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Uncommon){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Rare){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Rarer){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.SaughtAfter){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Legend){
                    lootList.Add (itemDatabase.items[i]);
                }
            }
            LootPicker(enemy);
            break;
        }
        case EnemyStats.EnemyType.Hard:{
            for(int i = 0; i < itemDatabase.items.Count; i++){
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Common){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Uncommon){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Rare){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Rarer){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.SaughtAfter){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Legend){
                    lootList.Add (itemDatabase.items[i]);
                }
            }
            LootPicker(enemy);
            break;
        }
        case EnemyStats.EnemyType.Supporter:{
            for(int i = 0; i < itemDatabase.items.Count; i++){
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Common){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Uncommon){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Rare){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Rarer){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.SaughtAfter){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Legend){
                    lootList.Add (itemDatabase.items[i]);
                }
            }
            LootPicker(enemy);
            break;
        }
        case EnemyStats.EnemyType.Devout:{
            for(int i = 0; i < itemDatabase.items.Count; i++){
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Rare){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Rarer){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.SaughtAfter){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Legend){
                    lootList.Add (itemDatabase.items[i]);
                }
            }
            LootPicker(enemy);
            break;
        }
        case EnemyStats.EnemyType.Hardned:{
            for(int i = 0; i < itemDatabase.items.Count; i++){
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Rare){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Rarer){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.SaughtAfter){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Legend){
                    lootList.Add (itemDatabase.items[i]);
                }
            }
            LootPicker(enemy);
            break;
        }
        case EnemyStats.EnemyType.Crazed:{
            for(int i = 0; i < itemDatabase.items.Count; i++){
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Rare){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Rarer){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.SaughtAfter){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Legend){
                    lootList.Add (itemDatabase.items[i]);
                }
            }
            LootPicker(enemy);
            break;
        }
        case EnemyStats.EnemyType.BadAss:{
            for(int i = 0; i < itemDatabase.items.Count; i++){
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Rare){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Rarer){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.SaughtAfter){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Legend){
                    lootList.Add (itemDatabase.items[i]);
                }
            }
            LootPicker(enemy);
            break;
        }
        case EnemyStats.EnemyType.WarForged:{
            for(int i = 0; i < itemDatabase.items.Count; i++){
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Rare){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Rarer){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.SaughtAfter){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Legend){
                    lootList.Add (itemDatabase.items[i]);
                }
            }
            LootPicker(enemy);
            break;
        }
        case EnemyStats.EnemyType.Insane:{
            for(int i = 0; i < itemDatabase.items.Count; i++){
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Rare){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Rarer){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.SaughtAfter){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Legend){
                    lootList.Add (itemDatabase.items[i]);
                }
            }
            LootPicker(enemy);
            break;
        }
        case EnemyStats.EnemyType.Zealot:{
            for(int i = 0; i < itemDatabase.items.Count; i++){
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Rare){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Rarer){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.SaughtAfter){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Legend){
                    lootList.Add (itemDatabase.items[i]);
                }
            }
            LootPicker(enemy);
            break;
        }
        case EnemyStats.EnemyType.RightHand:{
            break;
        }
        case EnemyStats.EnemyType.Boss:{
            break;
        }
        default:{
            break;
        }
        }
    }
    void LootPicker(Transform enemy){
        lootRNG = Random.Range (0.0f, 100.1f);
        pickerRNG = Random.Range (0, 22);
        if (lootRNG >= 50.0f && lootRNG <= 75.0f) {
            if(lootList[pickerRNG].itemRarity == Item.Rarity.Common){
                itemDrop.Add(lootList[pickerRNG]);
                MakeLoot(enemy);
            }
        }
        if(lootRNG > 75.0f && lootRNG <= 87.5f){
            if(lootList[pickerRNG].itemRarity == Item.Rarity.Uncommon){
                itemDrop.Add(lootList[pickerRNG]);
                MakeLoot(enemy);
            }
        }
        if(lootRNG < 93.7f && lootRNG >= 87.5f){
            if(lootList[pickerRNG].itemRarity == Item.Rarity.Rare){
                itemDrop.Add(lootList[pickerRNG]);
                MakeLoot(enemy);
            }
        }
        if(lootRNG < 97.0f && lootRNG >= 93.7f){
            if(lootList[pickerRNG].itemRarity == Item.Rarity.Rarer){
                itemDrop.Add(lootList[pickerRNG]);
                MakeLoot(enemy);
            }
        }
        if(lootRNG < 99.0f && lootRNG >= 97.0f){
            if(lootList[pickerRNG].itemRarity == Item.Rarity.SaughtAfter){
                itemDrop.Add(lootList[pickerRNG]);
                MakeLoot(enemy);
            }
        }
        if(lootRNG >= 99.0f){
            if(lootList[pickerRNG].itemRarity == Item.Rarity.Legend){
                itemDrop.Add(lootList[pickerRNG]);
                MakeLoot(enemy);
            }
        }
    }
    void MakeLoot(Transform target){
        Vector3 position = new Vector3(target.transform.localPosition.x, target.localPosition.y, 0);
        physicalLootPrefab = Instantiate(physicalLootPrefab, position, Quaternion.identity)as Rigidbody2D;
      
    }
}

am i manipulating the list indexes wrong?

I noticed you use brackets for cases, you shouldn’t (I didn’t even know you could do that lol!) ;

public void LootTable(Transform enemy, EnemyStats type){
        switch (type.enemyType){
        case EnemyStats.EnemyType.Lowly:
            lootList = new List<Item>();
            for(int i = 0; i < itemDatabase.items.Count; i++){
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Common){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Uncommon){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Rare){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Rarer){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.SaughtAfter){
                    lootList.Add (itemDatabase.items[i]);
                }
                if(itemDatabase.items[i].itemRarity == Item.Rarity.Legend){
                    lootList.Add (itemDatabase.items[i]);
                }
            }
            LootPicker(enemy);
        break;
        default:
            break;

        }
    }

But it doesn’t matter here.

What are the logs when you print the code I gave you ?

Can you show us “ItemDatabase” class ?

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class ItemDatabase : MonoBehaviour {

    public List<Item> items = new List<Item>();

    void Start(){
        items.Add (new Item("Green Potion", 1, "Heals Lex for 50 HP.", 0, 0, Item.ItemType.Consumable,Item.Element.None,Item.Sharpness.None, true, 5, 16, false, 50, 0, Item.Rarity.Common, true, 10, 200));
        items.Add (new Item("Meat",2,"A trading Resource.",0,0,Item.ItemType.Food,Item.Element.None,Item.Sharpness.None, false, 0, 0, false, 0, 0, Item.Rarity.Rare, true, 20, 999));
        items.Add (new Item("Plastic Shank",3,"Quick stabbing weapon.",0,0,Item.ItemType.LightWeapon,Item.Element.None,Item.Sharpness.Sharp, false,0,0, true, 0, 0, Item.Rarity.Common, false, 1, 1));
        items.Add (new Item("Nunchaku",4,"A fast blunt weapon.",0,0,Item.ItemType.MediumWeapon,Item.Element.None,Item.Sharpness.Blunt, false,0,0, true, 0, 0, Item.Rarity.Uncommon, false, 1, 1));
        items.Add (new Item("Blackberry",5,"Material for potions.",0,0,Item.ItemType.Ingredient,Item.Element.None,Item.Sharpness.None, false,0,0, false, 0, 0, Item.Rarity.Common, true, 10, 200));
        items.Add (new Item("Blueberry",6,"Material for potion, it looks sad.",0,0,Item.ItemType.Ingredient,Item.Element.None,Item.Sharpness.None, false, 0,0,false, 0, 0, Item.Rarity.Common, true, 10, 200));
        items.Add (new Item("Boysenberry",7,"Material for potions.",0,0,Item.ItemType.Ingredient,Item.Element.None,Item.Sharpness.None, false,0,0, false, 0, 0, Item.Rarity.Common, true, 10, 200));
        items.Add (new Item("Currant Berry",8,"Material for potions.",0,0,Item.ItemType.Ingredient,Item.Element.None,Item.Sharpness.None, false,0,0, false, 0, 0, Item.Rarity.Rarer, true, 10, 200));
        items.Add (new Item("Elderberry",9,"Material for potions.",0,0,Item.ItemType.Ingredient,Item.Element.None,Item.Sharpness.None, false,0,0, false, 0, 0, Item.Rarity.Common, true, 10, 200));
        items.Add (new Item("Salmonberry",10,"Material for potions.",0,0,Item.ItemType.Ingredient,Item.Element.None,Item.Sharpness.None, false,0,0, false, 0, 0, Item.Rarity.Common, true, 10, 200));
        items.Add (new Item("Sea-Buckthorn Berry",11,"Material for potions.",0,0,Item.ItemType.Ingredient,Item.Element.None,Item.Sharpness.None,false,0,0, false, 0, 0, Item.Rarity.Common, true, 10, 200));
        items.Add (new Item("Dave, the great and powerful",12,"Bestows deminion over the dead, and is a great apple slicer!",0,0,Item.ItemType.HeavyWeapon,Item.Element.None,Item.Sharpness.None,false,0,0, true, 0, 0, Item.Rarity.Legend, false, 1, 1));
        items.Add (new Item("Natural Diamond",13, "Used as a material for item upgrades", 0, 0, Item.ItemType.Ingredient,Item.Element.None,Item.Sharpness.None,false,0,0, false, 0, 0, Item.Rarity.SaughtAfter, true, 10, 200));
        items.Add (new Item("European Cut Diamond", 14, "Increases Intellect by 4", 0, 0, Item.ItemType.Jewel,Item.Element.None,Item.Sharpness.None, true,13,17, true, 8, 0, Item.Rarity.Rare, true, 10, 200));
        items.Add (new Item("Point Cut Diamond", 15, "Intellect +4\nEnergy regeneration +4", 0, 0, Item.ItemType.Jewel,Item.Element.None,Item.Sharpness.None, true,13,17, false, 4, 4, Item.Rarity.Rare, true, 10, 200));
        items.Add (new Item("Tea",16,"Delicious tea? or deadly poison..",0,0,Item.ItemType.Ingredient,Item.Element.None,Item.Sharpness.None, false,0,0, false, 0, 0, Item.Rarity.Common, true, 10, 200));
        items.Add (new Item("Iron Ore",17,"Rock with iron bits in it.",0,0,Item.ItemType.Ingredient,Item.Element.None,Item.Sharpness.None, false, 0,0, false, 0, 0, Item.Rarity.Uncommon, true, 10, 200));
        items.Add (new Item("Venom", 19, "Slightly increase attack power for one mission", 0, 0, Item.ItemType.Consumable,Item.Element.None,Item.Sharpness.None, true, 6, 8, false, 5, 0, Item.Rarity.Rarer, true, 10, 200));
        items.Add (new Item("Stone soup", 20, "Slightly increase attack power for one mission", 0, 0, Item.ItemType.Consumable,Item.Element.None,Item.Sharpness.None, true, 5, 8, false, 5, 0, Item.Rarity.Common, true, 10, 200));
        items.Add (new Item("Hot soup", 21, "Fire negate", 0, 0, Item.ItemType.Consumable,Item.Element.None,Item.Sharpness.None, true, 11, 16, false, 5, 23, Item.Rarity.Common, true, 10, 200));
        items.Add (new Item("Freezy", 22, "Fire protection for short period", 0, 0, Item.ItemType.Consumable,Item.Element.None,Item.Sharpness.None, true, 10, 23, false, 5, 0, Item.Rarity.Rare, true, 10, 200));
        items.Add (new Item("Ginseng", 23, "Herb", 0, 0, Item.ItemType.Ingredient,Item.Element.None,Item.Sharpness.None, false, 0, 0, false, 0, 0, Item.Rarity.Common, true, 10, 200));
    }
    public Item GetItem(string name, int id){
        for (int i=0; i < items.Count; i++) {
            if(items[i].itemName == name){
                return items[i];
            }
            if(items[i].itemID == id){
                return items[i];
            }
        }
        return null;
    }
}

this is the product of the debugs you wanted
items in list: 22
lootRNG: 7.430323, pickerRNG: 12

also, the loot gameobject that is instantiated:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class LootInWorld : MonoBehaviour {
    public Loot loot;
    public ItemDatabase itemdatabase;
    public Inventory inventory;
    public Texture2D texture;
    public Item thisItem;


    void Start () {
        loot = GameObject.Find("GameManager").GetComponent<Loot>();
        inventory =  GameObject.Find("GameManager").GetComponent<Inventory>();
        itemdatabase = GameObject.Find("GameManager").GetComponent<ItemDatabase>();
        FindItem ();
       
    }
    public void PickupItem(){
        if(inventory.CheckForSpace(thisItem.itemID) == true){
            inventory.AddItem (thisItem, 1);
            Debug.Log ("item added");
            gameObject.SetActive (false);
        }
    }
    void FindItem(){
        for(int i = 0; i < loot.itemDrop.Count; i++){
            if(loot.itemDrop[i].itemID >= 0){
                for(int j = 0; j < itemdatabase.items.Count; j++){
                    if(loot.itemDrop[i].itemID == itemdatabase.items[j].itemID){
                        thisItem = itemdatabase.items[i];
                        loot.itemDrop = new List<Item>();
                        break;
                    }
                }
                texture = thisItem.itemIcon;
                gameObject.renderer.material.mainTexture = texture;
                break;
            }//else gameObject.SetActive(false);
        }
    }
    void OnTriggerStay2D(Collider2D other){
        if (other.gameObject.tag == "Player") {
            PickupItem ();
        }
    }
}

lootList and itemDrop are not well initialized ;

lootList is initialized only when your enemy is “Lowly” and itemDrop is never initialized, so when you’ll add an item, it will throw an exception.

    public List<Item> lootList = new List<Item>();
    public List<Item> itemDrop = new List<Item>();

so i

have to fill it with empty items before i fill it? hrm, ill try that

still only green potions.
tested it 5 times, dropped 7 items total with 12 enemies in each iteration.