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


C# Random.NextString方法代码示例

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


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

示例1: GenerateRandomAccountCollection

        private EntityCollection GenerateRandomAccountCollection()
        {
            var collection = new List<Entity>();
            for (var i = 0; i < 10; i++)
            {
                var rgn = new Random((int)DateTime.Now.Ticks);
                var entity = new Entity("account");
                entity["accountid"] = entity.Id = Guid.NewGuid();
                entity["address1_addressid"] = Guid.NewGuid();
                entity["modifiedon"] = DateTime.Now;
                entity["lastusedincampaign"] = DateTime.Now;
                entity["donotfax"] = rgn.NextBoolean();
                entity["new_verybignumber"] = rgn.NextInt64();
                entity["exchangerate"] = rgn.NextDecimal();
                entity["address1_latitude"] = rgn.NextDouble();
                entity["numberofemployees"] = rgn.NextInt32();
                entity["primarycontactid"] = new EntityReference("contact", Guid.NewGuid());
                entity["revenue"] = new Money(rgn.NextDecimal());
                entity["ownerid"] = new EntityReference("systemuser", Guid.NewGuid());
                entity["industrycode"] = new OptionSetValue(rgn.NextInt32());
                entity["name"] = rgn.NextString(15);
                entity["description"] = rgn.NextString(300);
                entity["statecode"] = new OptionSetValue(rgn.NextInt32());
                entity["statuscode"] = new OptionSetValue(rgn.NextInt32());
                collection.Add(entity);
            }

            return new EntityCollection(collection);
        }
开发者ID:guusvanw,项目名称:Guus.Xrm,代码行数:29,代码来源:GenericXrmServiceTest.cs

示例2: RedisClusterAsync

        private static async Task RedisClusterAsync()
        {
            var redisCluster = await Cluster.From(_host, _port, GetClusterConfiguration());

            var tasks = new List<Task>();

            for (var x = 0; x < 50; x++)
            {
                var threadnum = x;
                tasks.Add(Task.Run(async () =>
                {
                    try
                    {
                        for (var i = 0; i < 100; i++)
                        {
                            var rand = new Random(_seed + threadnum);
                            for (var s = 0; s < 10; s++)
                            {
                                var key = rand.NextString(150);
                                var max = 1;

                                if (HashSlot.For(key).ToInt() < HashSlot.SlotCount/2)
                                    max = 70;

                                for (var it = 0; it < max; it++)
                                {
                                    Write(await redisCluster.SendAsync(
                                        ClusterCommand.From("SET", key, rand.NextString(50)),
                                        MasterSlavePreference.Either));

                                    Write(await redisCluster.SendAsync(
                                        ClusterCommand.From("GET", key),
                                        MasterSlavePreference.Either));
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("EXCEPTION: " + e.Message);
                        throw;
                    }
                    finally
                    {
                        Console.WriteLine("THREAD EXIT");
                    }
                }));
            }

            var t = new Timer((a) =>
            {
                Console.WriteLine("Time for new bytes!");
                _seed++;
            }, new {}, 0, 30000);

            Task.WaitAll(tasks.ToArray());
        }
开发者ID:searbe,项目名称:redis-client,代码行数:57,代码来源:Program.cs

示例3: GetNextStringTest

 public void GetNextStringTest()
 {
     int expectedLenght = 1000;
     var random = new Random();
     string actual = random.NextString(expectedLenght);
     Assert.AreEqual(expectedLenght, actual.Length);
 }
开发者ID:oleksii-mdr,项目名称:SimpleStringBuilder,代码行数:7,代码来源:RandomStringTest.cs

示例4: NextString_LengthGreaterThanZero

		public void NextString_LengthGreaterThanZero()
		{
			Random r = new Random();
			string str = r.NextString(10);

			Assert.AreEqual(str.Length, 10);
		}
开发者ID:flashcurd,项目名称:Shared.Utilities,代码行数:7,代码来源:RandomExtensionsTests.cs

示例5: NextString_LengthZero

		public void NextString_LengthZero()
		{
			Random r = new Random();
			string str = r.NextString(0);

			Assert.AreEqual(str, string.Empty);
		}
开发者ID:flashcurd,项目名称:Shared.Utilities,代码行数:7,代码来源:RandomExtensionsTests.cs

示例6: GenerateRandomTestEntities

 public static List<TestEntity> GenerateRandomTestEntities(int sampleSize)
 {
     Random random = new Random();
     List<TestEntity> testEntities = new List<TestEntity>();
     for (int i = 0; i < sampleSize; i++)
     {
         testEntities.Add(new TestEntity
         {
             TestDate = random.NextDateTime(new DateTime(2000, 1, 1), new DateTime(2012, 1, 1)),
             TestInt = random.Next(),
             TestString = random.NextString(1000)
         });
     }
     return testEntities;
 }
开发者ID:bingdianfeishui,项目名称:StaticVoid.OrmPerformance,代码行数:15,代码来源:TestEntityHelpers.cs

示例7: RandomPhone

 private static string RandomPhone(int seed)
 {
     Random r = new Random(seed);
     return r.NextString(10, "0123456789");
 }
开发者ID:otamimi,项目名称:southwind,代码行数:5,代码来源:SouthwindEnvironment.cs

示例8: RandomAddress

 private static AddressEntity RandomAddress(int seed)
 {
     Random r = new Random(seed);
     return new AddressEntity
     {
         Address = r.NextElement(new[] { "Madison Av.", "Sessame Str.", "5th Av.", "Flamingo Way" }) + " " + r.Next(100),
         City = r.NextElement(new[] { "New York", "Los Angeles", "Miami", "Seattle" }),
         Country = "USA",
         Region = r.NextElement(new[] { "NY", "FL", "WA", "CA" }),
         PostalCode = r.NextString(5, "0123456789")
     };
 }
开发者ID:otamimi,项目名称:southwind,代码行数:12,代码来源:SouthwindEnvironment.cs

示例9: MockHttpServerUtility

		public MockHttpServerUtility()
		{
			Random rand = new Random();
			tmpDirectory = Path.Combine(Path.GetTempPath(), rand.NextString(5, 6, "qwertyuiopasdfghjklzxcvbnm"));
			Directory.CreateDirectory(tmpDirectory);
		}
开发者ID:holtsoftware,项目名称:Sannel.SVGHandler,代码行数:6,代码来源:MockHttpServerUtility.cs

示例10: NextString_LengthLessThanZero

		public void NextString_LengthLessThanZero()
		{
			Random r = new Random();
			r.NextString(-1);
		}
开发者ID:flashcurd,项目名称:Shared.Utilities,代码行数:5,代码来源:RandomExtensionsTests.cs

示例11: RptInvoiceControl_Load

 private void RptInvoiceControl_Load(object sender, EventArgs e)
 {
     Random random = new Random();
     this.invoiceNo = random.NextString(10);
     etNo.Text = this.invoiceNo;
 }
开发者ID:ViniciusConsultor,项目名称:mas-app,代码行数:6,代码来源:RptInvoiceControl.cs


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