本文整理汇总了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);
}
示例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());
}
示例3: GetNextStringTest
public void GetNextStringTest()
{
int expectedLenght = 1000;
var random = new Random();
string actual = random.NextString(expectedLenght);
Assert.AreEqual(expectedLenght, actual.Length);
}
示例4: NextString_LengthGreaterThanZero
public void NextString_LengthGreaterThanZero()
{
Random r = new Random();
string str = r.NextString(10);
Assert.AreEqual(str.Length, 10);
}
示例5: NextString_LengthZero
public void NextString_LengthZero()
{
Random r = new Random();
string str = r.NextString(0);
Assert.AreEqual(str, string.Empty);
}
示例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;
}
示例7: RandomPhone
private static string RandomPhone(int seed)
{
Random r = new Random(seed);
return r.NextString(10, "0123456789");
}
示例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")
};
}
示例9: MockHttpServerUtility
public MockHttpServerUtility()
{
Random rand = new Random();
tmpDirectory = Path.Combine(Path.GetTempPath(), rand.NextString(5, 6, "qwertyuiopasdfghjklzxcvbnm"));
Directory.CreateDirectory(tmpDirectory);
}
示例10: NextString_LengthLessThanZero
public void NextString_LengthLessThanZero()
{
Random r = new Random();
r.NextString(-1);
}
示例11: RptInvoiceControl_Load
private void RptInvoiceControl_Load(object sender, EventArgs e)
{
Random random = new Random();
this.invoiceNo = random.NextString(10);
etNo.Text = this.invoiceNo;
}