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


C# RandomGenerator类代码示例

本文整理汇总了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();
        }
开发者ID:revelly,项目名称:TDD_Training_Oct_15,代码行数:7,代码来源:GuessGameEngine.cs

示例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 };
		}
开发者ID:EmilZhou,项目名称:ConfuserEx,代码行数:7,代码来源:CipherGenContext.cs

示例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"
            };
        }
开发者ID:reexjungle,项目名称:xcal,代码行数:30,代码来源:shared.factory.cs

示例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>();
		}
开发者ID:EmilZhou,项目名称:ConfuserEx,代码行数:11,代码来源:APIStore.cs

示例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();
        }
开发者ID:revelly,项目名称:TDD_Training_Oct_15,代码行数:32,代码来源:Program.cs

示例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();
		}
开发者ID:EmilZhou,项目名称:ConfuserEx,代码行数:28,代码来源:ExpressionGenerator.cs

示例7: ShouldDecideNegatively

        public void ShouldDecideNegatively()
        {
            var generator = new RandomGenerator(() => 0.9);
            bool decision = generator.Decide(0.3);

            Assert.That(decision, Is.False);
        }
开发者ID:MilenPavlov,项目名称:EuroManager,代码行数:7,代码来源:RandomGeneratorTests.cs

示例8: ShouldDecidePositively

        public void ShouldDecidePositively()
        {
            var generator = new RandomGenerator(() => 0.2);
            bool decision = generator.Decide(0.3);

            Assert.That(decision, Is.True);
        }
开发者ID:MilenPavlov,项目名称:EuroManager,代码行数:7,代码来源:RandomGeneratorTests.cs

示例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));
        }
开发者ID:MilenPavlov,项目名称:EuroManager,代码行数:7,代码来源:RandomGeneratorTests.cs

示例10: 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

示例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);
                }

            }
        }
开发者ID:JuanCastillo,项目名称:Calculadoras,代码行数:31,代码来源:UnitTest1.cs

示例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;
		}
开发者ID:EmilZhou,项目名称:ConfuserEx,代码行数:8,代码来源:NormalEncoding.cs

示例13: NextValueThrowsExceptionWithUnsupportedTypeTest

        public void NextValueThrowsExceptionWithUnsupportedTypeTest()
        {
            var target = new RandomGenerator();

            Action action = () => target.NextValue('C', 'C');

            action.ShouldThrow<NotSupportedException>();
        }
开发者ID:roryprimrose,项目名称:ModelBuilder,代码行数:8,代码来源:RandomGeneratorExtensionTests.cs

示例14: NextValueThrowsExceptionWhenMinimumGreaterThanMaximumTest

        public void NextValueThrowsExceptionWhenMinimumGreaterThanMaximumTest()
        {
            var target = new RandomGenerator();

            Action action = () => target.NextValue(1, 0);

            action.ShouldThrow<ArgumentOutOfRangeException>();
        }
开发者ID:roryprimrose,项目名称:ModelBuilder,代码行数:8,代码来源:RandomGeneratorExtensionTests.cs

示例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];
        }
开发者ID:roryprimrose,项目名称:ModelBuilder,代码行数:12,代码来源:TestData.cs


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