本文整理汇总了C#中RandomGenerator类的典型用法代码示例。如果您正苦于以下问题:C# RandomGenerator类的具体用法?C# RandomGenerator怎么用?C# RandomGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RandomGenerator类属于命名空间,在下文中一共展示了RandomGenerator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: generateRandomNumber
public int generateRandomNumber()
{
if (randomGenerator == null)
randomGenerator = new RandomGenerator();
return RandomNumber = randomGenerator.getRandomNumber();
}
示例2: CipherGenContext
public CipherGenContext(RandomGenerator random, int dataVarCount) {
this.random = random;
Block = new StatementBlock(); // new LoopStatement() { Begin = 0, Limit = 4 };
dataVars = new Variable[dataVarCount];
for (int i = 0; i < dataVarCount; i++)
dataVars[i] = new Variable("v" + i) { Tag = i };
}
示例3: SharedFactory
public SharedFactory()
{
rndGenerator = new RandomGenerator();
prefixes = new List<string>
{
"http",
"https",
"ftp",
"ftps",
"sftp",
};
suffixes = new List<string>
{
"com",
"edu",
"org",
"ca",
"de",
"es",
"fr",
"it",
"pl",
"ir",
"ro",
"co.uk",
"net"
};
}
示例4: APIStore
/// <summary>
/// Initializes a new instance of the <see cref="APIStore" /> class.
/// </summary>
/// <param name="context">The working context.</param>
public APIStore(ConfuserContext context) {
this.context = context;
random = context.Registry.GetService<IRandomService>().GetRandomGenerator("APIStore");
dataStores = new SortedList<int, List<IDataStore>>();
predicates = new List<IOpaquePredicateDescriptor>();
}
示例5: Main
static void Main(string[] args)
{
GuessGameEngine gameEngine = new GuessGameEngine();
RandomGenerator ran = new RandomGenerator();
ran.StartPoint = 50;
ran.EndPoint = 100;
gameEngine.randomGenerator = ran;
gameEngine.startGame();
Console.WriteLine("Enter number between 1 - 100");
while (true)
{
int userInput = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(gameEngine.verifyGuess(userInput));
if (gameEngine.isGameEnded)
{
Console.WriteLine("Do you want to continue?");
var vote = Console.ReadLine().ToString();
if (vote.ToLower() == "yes")
{
Console.WriteLine("Enter number between 1 - 100");
gameEngine.restart();
}
else
break;
}
}
Console.ReadKey();
}
示例6: 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();
}
示例7: ShouldDecideNegatively
public void ShouldDecideNegatively()
{
var generator = new RandomGenerator(() => 0.9);
bool decision = generator.Decide(0.3);
Assert.That(decision, Is.False);
}
示例8: ShouldDecidePositively
public void ShouldDecidePositively()
{
var generator = new RandomGenerator(() => 0.2);
bool decision = generator.Decide(0.3);
Assert.That(decision, Is.True);
}
示例9: ShouldGiveMiddleValue
public void ShouldGiveMiddleValue()
{
var generator = new RandomGenerator(() => 0.5);
double value = generator.Value(3, 7);
Assert.That(value, Is.InRange(5.0 - Delta, 5.0 + Delta));
}
示例10: Initialize
public override void Initialize(RandomGenerator random) {
if (random.NextInt32(3) == 0)
Mask = 0xffffffff;
else
Mask = random.NextUInt32();
Key = random.NextUInt32() | 1;
}
示例11: TestCalculadora
public void TestCalculadora()
{
RandomGenerator r = new RandomGenerator();
var persons = Builder<Person>.CreateListOfSize(tests * tests).
All().With(x => x.Age = r.Next(0, 100))
.And(x => x.Height = r.Next(90, 180))
.And(x => x.Weight = r.Next(10, 90))
.And(x => x.IsMan = r.Next())
.And(x => x.BMR = r.Next(100, 2000))
.And(x => x.Hip = r.Next(20, 60))
.And(x => x.Waist = r.Next(20, 60))
.And(x => x.Neck = r.Next(10, 30))
.Random(15).With(x => x.BMR = 0.0f)
.Build();
foreach (Person p in persons)
{
Calculadora c = new Calculadora(p);
int value = r.Next(-5, 7);
if (value < 1 || value > 5)
{
Assert.IsFalse(c.seleccionarCalculadora(value.ToString()));
}
else
{
Assert.IsTrue(c.seleccionarCalculadora(value.ToString()));
if (value == 5)
Assert.IsFalse(c.estaActiva);
}
}
}
示例12: 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;
}
示例13: NextValueThrowsExceptionWithUnsupportedTypeTest
public void NextValueThrowsExceptionWithUnsupportedTypeTest()
{
var target = new RandomGenerator();
Action action = () => target.NextValue('C', 'C');
action.ShouldThrow<NotSupportedException>();
}
示例14: NextValueThrowsExceptionWhenMinimumGreaterThanMaximumTest
public void NextValueThrowsExceptionWhenMinimumGreaterThanMaximumTest()
{
var target = new RandomGenerator();
Action action = () => target.NextValue(1, 0);
action.ShouldThrow<ArgumentOutOfRangeException>();
}
示例15: NextPerson
/// <summary>
/// Returns a random person from the test data set.
/// </summary>
/// <returns>A random person.</returns>
public static Person NextPerson()
{
var generator = new RandomGenerator();
var index = generator.NextValue(0, People.Count - 1);
return People[index];
}