当前位置: 首页>>代码示例>>C#>>正文


C# RandomGenerator.NextInt32方法代码示例

本文整理汇总了C#中RandomGenerator.NextInt32方法的典型用法代码示例。如果您正苦于以下问题:C# RandomGenerator.NextInt32方法的具体用法?C# RandomGenerator.NextInt32怎么用?C# RandomGenerator.NextInt32使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RandomGenerator的用法示例。


在下文中一共展示了RandomGenerator.NextInt32方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateExpression

		static Expression GenerateExpression(RandomGenerator random, Expression current, int currentDepth, int targetDepth) {
			if (currentDepth == targetDepth || (currentDepth > targetDepth / 3 && random.NextInt32(100) > 85))
				return current;

			switch ((ExpressionOps)random.NextInt32(6)) {
				case ExpressionOps.Add:
					return GenerateExpression(random, current, currentDepth + 1, targetDepth) +
					       GenerateExpression(random, (LiteralExpression)random.NextUInt32(), currentDepth + 1, targetDepth);

				case ExpressionOps.Sub:
					return GenerateExpression(random, current, currentDepth + 1, targetDepth) -
					       GenerateExpression(random, (LiteralExpression)random.NextUInt32(), currentDepth + 1, targetDepth);

				case ExpressionOps.Mul:
					return GenerateExpression(random, current, currentDepth + 1, targetDepth) * (LiteralExpression)(random.NextUInt32() | 1);

				case ExpressionOps.Xor:
					return GenerateExpression(random, current, currentDepth + 1, targetDepth) ^
					       GenerateExpression(random, (LiteralExpression)random.NextUInt32(), currentDepth + 1, targetDepth);

				case ExpressionOps.Not:
					return ~GenerateExpression(random, current, currentDepth + 1, targetDepth);

				case ExpressionOps.Neg:
					return -GenerateExpression(random, current, currentDepth + 1, targetDepth);
			}
			throw new UnreachableException();
		}
开发者ID:EmilZhou,项目名称:ConfuserEx,代码行数:28,代码来源:ExpressionGenerator.cs

示例2: Initialize

		public override void Initialize(RandomGenerator random) {
			if (random.NextInt32(3) == 0)
				Mask = 0xffffffff;
			else
				Mask = random.NextUInt32();
			Key = random.NextUInt32() | 1;
		}
开发者ID:EmilZhou,项目名称:ConfuserEx,代码行数:7,代码来源:Swap.cs

示例3: GetKey

		Tuple<int, int> GetKey(RandomGenerator random, MethodDef init) {
			Tuple<int, int> ret;
			if (!keys.TryGetValue(init, out ret)) {
				int key = random.NextInt32() | 1;
				keys[init] = ret = Tuple.Create(key, (int)MathsUtils.modInv((uint)key));
			}
			return ret;
		}
开发者ID:EmilZhou,项目名称:ConfuserEx,代码行数:8,代码来源:NormalEncoding.cs

示例4: Initialize

		public override void Initialize(RandomGenerator random) {
			Operation = (CryptoNumOps)(random.NextInt32(4));
			switch (Operation) {
				case CryptoNumOps.Add:
				case CryptoNumOps.Xor:
					Key = InverseKey = random.NextUInt32();
					break;
				case CryptoNumOps.Mul:
					Key = random.NextUInt32() | 1;
					InverseKey = MathsUtils.modInv(Key);
					break;
				case CryptoNumOps.Xnor:
					Key = random.NextUInt32();
					InverseKey = ~Key;
					break;
			}
		}
开发者ID:EmilZhou,项目名称:ConfuserEx,代码行数:17,代码来源:NumOp.cs

示例5: GenerateUnimodularMatrix

		static uint[,] GenerateUnimodularMatrix(RandomGenerator random) {
			Func<uint> next = () => (uint)random.NextInt32(4);

			uint[,] l = {
				{ 1, 0, 0, 0 },
				{ next(), 1, 0, 0 },
				{ next(), next(), 1, 0 },
				{ next(), next(), next(), 1 }
			};
			uint[,] u = {
				{ 1, next(), next(), next() },
				{ 0, 1, next(), next() },
				{ 0, 0, 1, next() },
				{ 0, 0, 0, 1 }
			};

			return mul(l, u);
		}
开发者ID:EmilZhou,项目名称:ConfuserEx,代码行数:18,代码来源:Matrix.cs

示例6: Run

        public static void Run(StatementBlock block, RandomGenerator random)
        {
            var context = new TransformContext {
                Statements = block.Statements.ToArray(),
                Usages = block.Statements.ToDictionary(s => s, s => GetVariableUsage(s).ToArray()),
                Definitions = block.Statements.ToDictionary(s => s, s => GetVariableDefinition(s).ToArray())
            };
            for (int i = 0; i < ITERATION; i++) {
                foreach (Statement st in context.Statements) {
                    int index = block.Statements.IndexOf(st);
                    Variable[] vars = GetVariableUsage(st).Concat(GetVariableDefinition(st)).ToArray();

                    // Statement can move between defIndex & useIndex without side effects
                    int defIndex = SearchUpwardKill(context, st, block, index);
                    int useIndex = SearchDownwardKill(context, st, block, index);

                    // Move to a random spot in the interval
                    int newIndex = defIndex + random.NextInt32(1, useIndex - defIndex);
                    if (newIndex > index) newIndex--;
                    block.Statements.RemoveAt(index);
                    block.Statements.Insert(newIndex, st);
                }
            }
        }
开发者ID:89sos98,项目名称:ConfuserEx,代码行数:24,代码来源:ShuffleTransform.cs

示例7: Initialize

 public override void Initialize(RandomGenerator random)
 {
     Operation = (CryptoBinOps)random.NextInt32(3);
 }
开发者ID:GavinHwa,项目名称:ConfuserEx,代码行数:4,代码来源:BinOp.cs

示例8: Initialize

 public override void Initialize(RandomGenerator random)
 {
     Bits = random.NextInt32(1, 32);
     IsAlternate = (random.NextInt32() % 2 == 0);
 }
开发者ID:89sos98,项目名称:ConfuserEx,代码行数:5,代码来源:RotateBit.cs

示例9: HandleInject

		public void HandleInject(AntiTamperProtection parent, ConfuserContext context, ProtectionParameters parameters) {
			this.context = context;
			random = context.Registry.GetService<IRandomService>().GetRandomGenerator(parent.FullId);
			z = random.NextUInt32();
			x = random.NextUInt32();
			c = random.NextUInt32();
			v = random.NextUInt32();
			name1 = random.NextUInt32() & 0x7f7f7f7f;
			name2 = random.NextUInt32() & 0x7f7f7f7f;
			key = random.NextUInt32();

			fieldLayout = new byte[6];
			for (int i = 0; i < 6; i++) {
				int index = random.NextInt32(0, 6);
				while (fieldLayout[index] != 0)
					index = random.NextInt32(0, 6);
				fieldLayout[index] = (byte)i;
			}

			switch (parameters.GetParameter(context, context.CurrentModule, "key", Mode.Normal)) {
				case Mode.Normal:
					deriver = new NormalDeriver();
					break;
				case Mode.Dynamic:
					deriver = new DynamicDeriver();
					break;
				default:
					throw new UnreachableException();
			}
			deriver.Init(context, random);

			var rt = context.Registry.GetService<IRuntimeService>();
			TypeDef initType = rt.GetRuntimeType("Confuser.Runtime.AntiTamperJIT");
			IEnumerable<IDnlibDef> defs = InjectHelper.Inject(initType, context.CurrentModule.GlobalType, context.CurrentModule);
			initMethod = defs.OfType<MethodDef>().Single(method => method.Name == "Initialize");

			initMethod.Body.SimplifyMacros(initMethod.Parameters);
			List<Instruction> instrs = initMethod.Body.Instructions.ToList();
			for (int i = 0; i < instrs.Count; i++) {
				Instruction instr = instrs[i];
				if (instr.OpCode == OpCodes.Ldtoken) {
					instr.Operand = context.CurrentModule.GlobalType;
				}
				else if (instr.OpCode == OpCodes.Call) {
					var method = (IMethod)instr.Operand;
					if (method.DeclaringType.Name == "Mutation" &&
					    method.Name == "Crypt") {
						Instruction ldDst = instrs[i - 2];
						Instruction ldSrc = instrs[i - 1];
						Debug.Assert(ldDst.OpCode == OpCodes.Ldloc && ldSrc.OpCode == OpCodes.Ldloc);
						instrs.RemoveAt(i);
						instrs.RemoveAt(i - 1);
						instrs.RemoveAt(i - 2);
						instrs.InsertRange(i - 2, deriver.EmitDerivation(initMethod, context, (Local)ldDst.Operand, (Local)ldSrc.Operand));
					}
				}
			}
			initMethod.Body.Instructions.Clear();
			foreach (Instruction instr in instrs)
				initMethod.Body.Instructions.Add(instr);

			MutationHelper.InjectKeys(initMethod,
			                          new[] { 0, 1, 2, 3, 4 },
			                          new[] { (int)(name1 * name2), (int)z, (int)x, (int)c, (int)v });

			var name = context.Registry.GetService<INameService>();
			var marker = context.Registry.GetService<IMarkerService>();

			cctor = context.CurrentModule.GlobalType.FindStaticConstructor();

			cctorRepl = new MethodDefUser(name.RandomName(), MethodSig.CreateStatic(context.CurrentModule.CorLibTypes.Void));
			cctorRepl.IsStatic = true;
			cctorRepl.Access = MethodAttributes.CompilerControlled;
			cctorRepl.Body = new CilBody();
			cctorRepl.Body.Instructions.Add(Instruction.Create(OpCodes.Ret));
			context.CurrentModule.GlobalType.Methods.Add(cctorRepl);
			name.MarkHelper(cctorRepl, marker, parent);

			MutationHelper.InjectKeys(defs.OfType<MethodDef>().Single(method => method.Name == "HookHandler"),
			                          new[] { 0 }, new[] { (int)key });
			foreach (IDnlibDef def in defs) {
				if (def.Name == "MethodData") {
					var dataType = (TypeDef)def;
					FieldDef[] fields = dataType.Fields.ToArray();
					var layout = fieldLayout.Clone() as byte[];
					Array.Sort(layout, fields);
					for (byte j = 0; j < 6; j++)
						layout[j] = j;
					Array.Sort(fieldLayout, layout);
					fieldLayout = layout;
					dataType.Fields.Clear();
					foreach (FieldDef f in fields)
						dataType.Fields.Add(f);
				}
				name.MarkHelper(def, marker, parent);
				if (def is MethodDef)
					parent.ExcludeMethod(context, (MethodDef)def);
			}
			parent.ExcludeMethod(context, cctor);
		}
开发者ID:EmilZhou,项目名称:ConfuserEx,代码行数:100,代码来源:JITMode.cs


注:本文中的RandomGenerator.NextInt32方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。