本文整理汇总了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();
}
示例2: Initialize
public override void Initialize(RandomGenerator random) {
if (random.NextInt32(3) == 0)
Mask = 0xffffffff;
else
Mask = random.NextUInt32();
Key = random.NextUInt32() | 1;
}
示例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;
}
示例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;
}
}
示例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);
}
示例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);
}
}
}
示例7: Initialize
public override void Initialize(RandomGenerator random)
{
Operation = (CryptoBinOps)random.NextInt32(3);
}
示例8: Initialize
public override void Initialize(RandomGenerator random)
{
Bits = random.NextInt32(1, 32);
IsAlternate = (random.NextInt32() % 2 == 0);
}
示例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);
}