當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。