當前位置: 首頁>>代碼示例>>C#>>正文


C# Random.NextDecimal方法代碼示例

本文整理匯總了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);
        }
開發者ID:guusvanw,項目名稱:Guus.Xrm,代碼行數:29,代碼來源:GenericXrmServiceTest.cs

示例2: CanSampleDecimal

 public void CanSampleDecimal()
 {
     var rnd = new Random();
     rnd.NextDecimal();
 }
開發者ID:XiBeichuan,項目名稱:hydronumerics,代碼行數:5,代碼來源:SystemRandomExtensionTests.cs

示例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;
//.........這裏部分代碼省略.........
開發者ID:YOTOV-LIMITED,項目名稱:CrmAdo,代碼行數:101,代碼來源:EntityDataGenerator.cs


注:本文中的System.Random.NextDecimal方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。