Esempio n. 1
0
        public static NETExpression CreateRandom(int intensity)
        {
            int positionValue = random.Next(0, intensity - 1);
            List <Instruction> instructions = new List <Instruction>();

            instructions.Add(OpCodes.Ldc_I4.ToInstruction(random.Next()));
            instructions.Add(OpCodes.Ldc_I4.ToInstruction(random.Next()));
            for (int i = 0; i < intensity; i++)
            {
                instructions.Add(GetRandomOperator().ToInstruction());
                if (positionValue == i)
                {
                    instructions.Add(OpCodes.Ldarg_0.ToInstruction());
                }
                else
                {
                    instructions.Add(OpCodes.Ldc_I4.ToInstruction(random.Next()));
                }
            }
            instructions.Add(GetRandomOperator().ToInstruction());
            instructions.Add(OpCodes.Ret.ToInstruction());
            return(new NETExpression()
            {
                Instructions = instructions
            });
        }
Esempio n. 2
0
        public static List <T> Shuffle <T>(List <T> array, out int[] position)
        {
            RandomGen rand = new RandomGen();
            List <KeyValuePair <int, T> > list = new List <KeyValuePair <int, T> >();

            foreach (T s in array)
            {
                list.Add(new KeyValuePair <int, T>(rand.Next(), s));
            }
            var sorted = from item in list
                         orderby item.Key
                         select item;

            T[] result = new T[array.Count];
            int index  = 0;

            foreach (KeyValuePair <int, T> pair in sorted)
            {
                result[index] = pair.Value;
                index++;
            }
            List <int> positions = new List <int>();

            for (int i = 0; i < array.Count; i++)
            {
                positions.Add(Array.IndexOf(array.ToArray(), result[i]));
            }
            position = positions.ToArray();
            return(result.ToList());
        }
Esempio n. 3
0
        public Instruction[] Create()
        {
            int positionValue = r.Next(0, intensity);
            List <Instruction> instructions = new List <Instruction>();

            instructions.Add(OpCodes.Ldc_I4.ToInstruction(r.Next()));
            instructions.Add(OpCodes.Ldc_I4.ToInstruction(r.Next()));
            for (int i = 0; i < intensity; i++)
            {
                instructions.Add(getRandomOperation().ToInstruction());
                if (positionValue == i)
                {
                    instructions.Add(OpCodes.Ldarg_0.ToInstruction());
                }
                else
                {
                    instructions.Add(OpCodes.Ldc_I4.ToInstruction(r.Next()));
                }
            }
            instructions.Add(getRandomOperation().ToInstruction());
            instructions.Add(OpCodes.Ret.ToInstruction());
            return(instructions.ToArray());
        }