本文整理汇总了C#中System.Random.NextDecimal方法的典型用法代码示例。如果您正苦于以下问题:C# Random.NextDecimal方法的具体用法?C# Random.NextDecimal怎么用?C# Random.NextDecimal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Random
的用法示例。
在下文中一共展示了Random.NextDecimal方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: CanSampleDecimal
public void CanSampleDecimal()
{
var rnd = new Random();
rnd.NextDecimal();
}
示例3: GenerateFakeEntities
public IList<Entity> GenerateFakeEntities(string entityName, int howMany)
{
var metadataProvider = _MetadataProvider;
var metadata = metadataProvider.GetEntityMetadata(entityName);
Random rand = new Random();
List<Entity> results = new List<Entity>();
// Used for generating random dates.
DateTime minCrmDate = new DateTime(1900, 1, 1);
int crmDayRange = (DateTime.Today - minCrmDate).Days;
for (int i = 0; i < howMany; i++)
{
var ent = new Microsoft.Xrm.Sdk.Entity(entityName);
ent.Id = Guid.NewGuid();
int stateCode = rand.Next(0, 1);
int statusCode = stateCode + 1;
foreach (var a in metadata.Attributes)
{
switch (a.AttributeType.Value)
{
case AttributeTypeCode.BigInt:
var randomBigInt = (long)rand.NextLong(0, Int64.MaxValue);
ent[a.LogicalName] = randomBigInt;
break;
case AttributeTypeCode.Boolean:
int randomBoolInt = rand.Next(0, 1);
ent[a.LogicalName] = randomBoolInt == 1;
break;
case AttributeTypeCode.CalendarRules:
break;
case AttributeTypeCode.Customer:
int randomCustomerInt = rand.Next(0, 1);
string customerentity = "contact";
Guid customerId = Guid.NewGuid();
if (randomCustomerInt == 1)
{
customerentity = "account";
}
EntityReference customerRef = new EntityReference(customerentity, customerId);
ent[a.LogicalName] = customerRef;
break;
case AttributeTypeCode.DateTime:
DateTime randomDate = rand.NextCrmDate(minCrmDate, crmDayRange);
ent[a.LogicalName] = randomDate;
break;
case AttributeTypeCode.Decimal:
var decAtt = (DecimalAttributeInfo)a;
var scale = decAtt.NumericScale;
byte byteScale = (byte)scale;
var randomDecimal = rand.NextDecimal(byteScale);
ent[a.LogicalName] = randomDecimal;
break;
case AttributeTypeCode.Double:
var doubleAtt = (DoubleAttributeInfo)a;
var doubleScale = doubleAtt.NumericScale;
byte byteDoubleScale = (byte)doubleScale;
// todo apply precision / scale
var randomDouble = rand.NextDouble();
ent[a.LogicalName] = randomDouble;
break;
case AttributeTypeCode.EntityName:
break;
case AttributeTypeCode.Integer:
ent[a.LogicalName] = rand.Next();
break;
case AttributeTypeCode.Lookup:
break;
case AttributeTypeCode.ManagedProperty:
break;
case AttributeTypeCode.Memo:
var randomMemoString = string.Format("Test Memo String {0}", DateTime.UtcNow.Ticks.ToString());
ent[a.LogicalName] = randomMemoString;
break;
case AttributeTypeCode.Money:
var moneyAtt = (MoneyAttributeInfo)a;
var mscale = moneyAtt.NumericScale;
byte bytemScale = (byte)mscale;
var randomMoneyDecimal = rand.NextDecimal(bytemScale);
var randMoney = new Money(randomMoneyDecimal);
ent[a.LogicalName] = randMoney;
break;
case AttributeTypeCode.Owner:
EntityReference ownerRef = new EntityReference("systemuser", Guid.NewGuid());
ent[a.LogicalName] = ownerRef;
break;
case AttributeTypeCode.PartyList:
break;
case AttributeTypeCode.Picklist:
OptionSetValue optValue = new OptionSetValue(rand.Next());
ent[a.LogicalName] = optValue;
break;
case AttributeTypeCode.State:
// todo randomise active and inactive.
var stateCodeOpt = new OptionSetValue(stateCode);
ent[a.LogicalName] = stateCodeOpt;
break;
//.........这里部分代码省略.........