using UnityEngine;
using System.Collections;

public class OrderRandomized : MonoBehaviour {


    public int RandomizeLenMin = 4;
    public int RandomizeLenMax = 16;

    public int RandomizeLen = 4;
    public int[] RandomizeList = null;

    public bool Randomize = false;

    public Create_Crystals CrystalDB = null;
    public int CrystalCnt = 0;


    // Use this for initialization
	void Start () {
        if (RandomizeLenMax > 0)
            RandomizeList = new int[RandomizeLenMax];

        CrystalDB = this.GetComponent<Create_Crystals>();
	
        // Do first Randomize
        Randomize = true;
        Update();

    }
	
	// Update is called once per frame
	void Update () {
        if (Randomize)
        { 
            Randomize = false;

            CrystalCnt = CrystalDB.crystal_list.Length;
            
           
            RandomizeLen++; //= Random.Range(RandomizeLenMin, RandomizeLenMax);

            if (RandomizeLen > CrystalCnt)
                RandomizeLen = CrystalCnt;

            if (RandomizeLen > RandomizeLenMax)
                RandomizeLen = RandomizeLenMax;
            

            for (int cur = 0; cur < RandomizeLen; cur++)
            {


                bool redo = false;
                int rand_item;

                do{
                    redo = false;
                    rand_item = Random.Range(0, CrystalCnt);
                    for(int a = 0; a < cur; a++)
                        if(RandomizeList[a] == rand_item)
                            redo = true;
                }while (redo);

                RandomizeList[cur] = rand_item;
                
            }

            //RandomizeLen = RandCur;
        
        }



	}
}
