• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# RandomGenerator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



RandomGenerator类属于命名空间,在下文中一共展示了RandomGenerator类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: IsSupportedThrowsExceptionWithNullTypeTest

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

            Action action = () => target.IsSupported(null);

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


示例17: NextMale

        /// <summary>
        /// Returns a random male from the test data set.
        /// </summary>
        /// <returns>A random male.</returns>
        public static Person NextMale()
        {
            var generator = new RandomGenerator();

            var index = generator.NextValue(0, Males.Count - 1);

            return Males[index];
        }
开发者ID:roryprimrose,项目名称:ModelBuilder,代码行数:12,代码来源:TestData.cs


示例18: Initialize

		public override void Initialize(RandomGenerator random) {
			InverseKey = mul(transpose4(GenerateUnimodularMatrix(random)), GenerateUnimodularMatrix(random));

			var cof = new uint[4, 4];
			for (int i = 0; i < 4; i++)
				for (int j = 0; j < 4; j++)
					cof[i, j] = cofactor4(InverseKey, i, j);
			Key = transpose4(cof);
		}
开发者ID:EmilZhou,项目名称:ConfuserEx,代码行数:9,代码来源:Matrix.cs


示例19: RandomBytesAreUnique

        public void RandomBytesAreUnique(byte min, byte max)
        {
            RandomGenerator r = new RandomGenerator(new Random().Next());
            byte[] values = new byte[10];
            for (int i = 0; i < 10; i++)
                values[i] = r.GetByte();

            Assert.That(values, Is.Unique);
        }
开发者ID:xplatform,项目名称:Portable.NUnitLite,代码行数:9,代码来源:RandomGeneratorTests.cs


示例20: ShouldChooseItemRandomly

        public void ShouldChooseItemRandomly()
        {
            int[] items = { 1, 2, 3 };
            
            var generator = new RandomGenerator(() => 0.4);
            int chosen = generator.Choose(items, 0.5, 1.0, 0.3);

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# RandomIndexWriter类代码示例发布时间:2022-05-24
下一篇:
C# Random类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap